sun博客

记录点滴!

接收get请求:

  @RequestMapping(value = "getxdso", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public String getSo(@RequestParam("input") String input){

        try {
            String result=MainActivity.encodeXdSo(input);
            return result;
        }catch (Exception e){
            return  "1";
        }

    }

接收post请求:

获取HTTP字符串body
String getBodytxt(HttpServletRequest request) {
	BufferedReader br = request.getReader();
	String str, wholeStr = "";
	while((str = br.readLine()) != null){
		wholeStr += str;
	}
	return wholeStr;
}
获取HTTP二进制body
private String getBodyData(HttpServletRequest request) {
	StringBuffer data = new StringBuffer();
	String line = null;
	BufferedReader reader = null;
	try {
		reader = request.getReader();
		while (null != (line = reader.readLine()))
			data.append(line);
	} catch (IOException e) {
	} finally {
	}
	return data.toString();
}
@RequestBody获取body
@RequestMapping(value = "/testurl", method = RequestMethod.POST)
@ResponseBody
public ServiceResult TestUrl(HttpServletRequest request,
	@RequestBody JSONObject jsonObject){
   String username =  jsonObject.get("username").toString();
   String pwd = jsonObject.get("pwd").toString();
}

@RequestBody 可以使用JSONObject, Map ,或者ObjectDTO绑定body。 
 public String getplaysignso(@RequestBody HashMap body){}


public ServiceResult TestUrl(HttpServletRequest request,
	@RequestBody HjsonObject){
   String username =  jsonObject.get("username").toString();
   String pwd = jsonObject.get("pwd").toString();
}

@RequestParam获取body
@RequestMapping(value = "/testurl", method = RequestMethod.POST)
@ResponseBody
public ServiceResult TestUrl(HttpServletRequest request,@RequestParam("username")String username,
@RequestParam("pwd")String pwd)  {
  String txt = username + pwd;
}

发表评论

邮箱地址不会被公开。 必填项已用*标注