zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    通过哪吒动漫豆瓣影评,带你分析python爬虫与BeautifulSoup快速入门
    带着canvas去流浪系列之九 粒子动画
    带着canvas去流浪系列之八 碰撞
    Python小数据保存,有多少中分类?不妨看看他们的类比与推荐方案...
    免费试用 | 多模 NoSQL 服务GeminiDB for Cassandra 全球首发
    Vue+ElementUI项目使用webpack输出MPA
    nmon
    补习系列(12)-springboot 与邮件发送
    从React 编程到"好莱坞"
    百度网盘API的操作--PCS 百度个人云存储 上传 ,下载文件
  • 原文地址:https://www.cnblogs.com/hujunzheng/p/6178049.html
Copyright © 2011-2022 走看看