fiddler發送post請求


1.指定為 post 請求,輸入 url

  Content-Type: application/x-www-form-urlencoded;charset=utf-8

  request body中的參數格式:userName=adminicxp&userPassword=123qwe!@#

   這種方式可以用 request.getParameter的方式來獲得。

2.指定為 post 請求,輸入 url

  Content-Type: application/json; charset=utf-8

  request body中的參數格式:

{
    "userName": "adminicxp",
    "userPassword": "123qwe!@#",
    "sysId": "xxx"
}

 

  這種方式通過如下方式獲得:

    @RequestMapping("/xxx")  
    @ResponseBody  
    public String xxx(HttpServletRequest request) throws IOException {  
  
        String jsonString = getBodyString(request.getReader());  
  
        JSONObject jbJsonObject = new JSONObject().fromObject(jsonString);  
  
        User user = (User) JSONObject.toBean(jbJsonObject, User.class);  
        System.out.println(jbJsonObject);  
        System.out.println("id:" + user.getUserName());return null;  
  
    }  
  
    @RequestMapping("/xxx2")  
    @ResponseBody  
    public String xxx2(User user) throws IOException {  
  
        System.out.println("---------------");  
        System.out.println(user.getUserName());  
        System.out.println(user.getPassWord());  
        System.out.println("---------------");  
  
        if (true) {  
            return "success";  
        } else {  
            return "fail";  
        }  
  
    }  

  

  public String getBodyString(BufferedReader br) {
    String inputLine;
    String str = "";
    try {
      while ((inputLine = br.readLine()) != null) {
      str += inputLine;
    }
      br.close();
    } catch (IOException e) {
      System.out.println("IOException: " + e);
    }
    return str;
  }

 

 3.post數組

  方式1:

  springmvc 后台java代碼

@RequestBody Map<String, List<String>> param

List<String> ids = param.get("ids");

  fiddler 請求

Content-Type指定為 application/json

RequestBody格式:{"ids":["first0001company", "xxx4234324"]}

 

  方式2:

  springmvc 后台java代碼

@RequestParam List<String> ids;

或者 @RequestParam String[] ids;

  fiddler 請求

Content-Type指定為 application/x-www-form-urlencoded

RequestBody格式:ids=first0001company&ids=xxx4234324

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM