zoukankan      html  css  js  c++  java
  • Curl Get请求&漏参数

    今天测试的时候mock一个站点的访问,使用curl调用一直报400,Bad Request,缺少参数。

    提示缺少参数,明明加了啊,参数使用&连接,仔细观察命令没有结束。因为linux中  &代表命令在后台执行,因此命令没有结束。

    使用wireshark抓包分析

    可以看到确实没有documentIds参数

    二种解决方案:

    1. 使用"" 把请求体包起来: curl -i  "http://localhost/v2/***"

    2. 使用转义   curl -i  http://localhost/v2/65/appid=4&documentIds=136,137

    说明:

    curl post请求:

    curl -H "Content-Type:application/json" -X POST -d '{"user": "admin", "passwd":"12345678"}' http://127.0.0.1:8000/login

     附上为了mock接口写的代码

    @RestController
    public class IDImgsController {
    
        @RequestMapping("/v2/DocumentService/getBatchDocuments/{id}")
        public String getImgs(@PathVariable Integer id, @RequestParam("appid") String appid, @RequestParam("documentIds") String documentIds){
            return "{
    " +
                    "  "data": [
    " +
                    "    {
    " +
                    "      "creation_date": "2018-09-07 14:24:04",
    " +
                    "      "document_id": 136,
    " +
                    "      "file_name": "二代身份证正面",
    " +
                    "      "front_document_id": 68,
    " +
                    "      "url": "http://f.ppdai.com/**.jpg",
    " +
                    "      "user_id": 8487008
    " +
                    "    },
    " +
                    "    {
    " +
                    "      "creation_date": "2018-09-07 14:24:15",
    " +
                    "      "document_id": 137,
    " +
                    "      "file_name": "二代身份证反面",
    " +
                    "      "front_document_id": 69,
    " +
                    "      "url": "http://file11info.ppdai.com/***.jpg",
    " +
                    "      "user_id": 8487008
    " +
                    "    },
    " +
                    "    {
    " +
                    "      "creation_date": "2018-09-07 14:24:31",
    " +
                    "      "document_id": 137,
    " +
                    "      "file_name": "二代身份证反面",
    " +
                    "      "front_document_id": 69,
    " +
                    "      "url": "http://file11info.ppdai.com/***.jpg",
    " +
                    "      "user_id": 8487008
    " +
                    "    },
    " +
                    "    {
    " +
                    "      "creation_date": "2018-09-07 14:24:54",
    " +
                    "      "document_id": 138,
    " +
                    "      "file_name": "本人手持二代身份证的合照",
    " +
                    "      "front_document_id": 70,
    " +
                    "      "url": "http://file11info.ppdai.com/***.jpg",
    " +
                    "      "user_id": 8487008
    " +
                    "    }
    " +
                    "  ],
    " +
                    "  "msg": "success",
    " +
                    "  "ret": 0,
    " +
                    "  "serial_no": "747a095e-f80e-4879-a288-f75e1e4bd73b"
    " +
                    "}";
        }
    }
    欢迎关注Java流水账公众号
  • 相关阅读:
    web开发(六) EL表达式
    web开发(五) JSP详解(四大作用域九大内置对象等)
    web开发(四) 一次性验证码的代码实现
    Netty4
    Android Fragment
    Android 6.0 双向通话自动录音
    安卓
    SpringMVC + Spring + Mybatis+ Redis +shiro以及MyBatis学习
    Spring 3 AOP 概念及完整示例
    Java并发之CountDownLatch、CyclicBarrier和Semaphore
  • 原文地址:https://www.cnblogs.com/guofu-angela/p/10877296.html
Copyright © 2011-2022 走看看