NutzCN Logo
问答 post请求调用接口时,偶然会出现中文乱码,header中缺失Cookie:sid
发布于 2566天前 作者 qq_b54b367e 2299 次浏览 复制 上一个帖子 下一个帖子
标签:
@IocBean
@At("/front/userInfo")
public class UserInfoController {
	@Inject
	private UserInfoService userInfoService;

	@At("/getUserInfoByIDNum")
	@Ok("json")
	@AdaptBy(type = JsonAdaptor.class)
	public Object getUserInfoByIDNum(@Param("idNum") String idNum) {
		if(Strings.isBlank(idNum)) {
			return Result.error("参数缺失");
		}
		return userInfoService.getUserInfoByIDNum(idNum);
	}

	@At("/saveUserInfo")
	@Ok("json")
	@AdaptBy(type = JsonAdaptor.class)
	public Object saveUserInfo(@Param("idNum") String idNum, @Param("name") String name,
			@Param("phoneNum") String phoneNum) {
		if (Strings.isBlank(idNum) || Strings.isBlank(name) || Strings.isBlank(phoneNum)) {
			return Result.error("参数缺失");
		}
		return userInfoService.saveUserInfo(idNum, name, phoneNum);
	}

}
@IocBean(args = { "refer:dao" })
public class UserInfoServiceImpl extends BaseServiceImpl<UserInfo> implements UserInfoService {

	private static final Log log = Logs.get();

	@Inject
	private UserInfoService userInfoService;

	public UserInfoServiceImpl(Dao dao) {
		super(dao);
	}

	@Override
	public Result getUserInfoByIDNum(String idNum) {
		UserInfo userInfo = this.fetch(idNum);
		if (userInfo == null) {
			return Result.error("查询不到相关数据");
		}
		return Result.success("ok", userInfo);

	}

	@Override
	public Result saveUserInfo(String idNum, String name, String phoneNum) {
		try {
			UserInfo dbInfo = this.fetch(idNum);
			if (dbInfo == null) {
				UserInfo userInfo = new UserInfo();
				userInfo.setId(idNum);
				userInfo.setName(name);
				userInfo.setPhoneNum(phoneNum);
				userInfo.setCreateDate(new Date());
				userInfo=this.insert(userInfo);
				return Result.success("ok", userInfo);
			} else {
				dbInfo.setId(idNum);
				dbInfo.setName(name);
				dbInfo.setPhoneNum(phoneNum);
				this.updateIgnoreNull(dbInfo);
				return Result.success("ok", dbInfo);
			}
		} catch (Exception e) {
			log.error(e.getMessage());
			return Result.error("插入或更新用户信息时出现异常");
		}
	}
}
5 回复

乱码跟缺cookie啥关系? 为啥联系在一起?

sid是啥?shiro吗?

你这是在狂刷页面?

因为抓接口的时候发现乱码的数据,header那里会缺失一个cookie参数

POST /onlineqs_tz/front/userInfo/saveUserInfo HTTP/1.1
Accept-Language: zh-CN,zh;q=0.8
User-Agent: Mozilla/5.0 (Linux; U; Android 6.0.1; zh-cn; QUAD-CORE R18 ads Build/MMB29M) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
Content-Type: application/x-www-form-urlencoded
Content-Length: 69
Host: 10.1.1.211 

Connection: Keep-Alive
Accept-Encoding: gzip
Cookie: sid=4ea2fbba-81ac-41e8-bfbf-33ff3df8a543

idNum=440921199212120011&name=%E8%81%8A%E8%81%8A&phoneNum=15119612001

问题觉得与https://nutz.cn/yvr/t/qqj3hsmrpohlrrav36og0mj2df类似

那你就加WhaleFilter嘛,文档有

添加回复
请先登陆
回到顶部