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 "{\n" +
                "  \"data\": [\n" +
                "    {\n" +
                "      \"creation_date\": \"2018-09-07 14:24:04\",\n" +
                "      \"document_id\": 136,\n" +
                "      \"file_name\": \"二代身份证正面\",\n" +
                "      \"front_document_id\": 68,\n" +
                "      \"url\": \"http://f.ppdai.com/**.jpg\",\n" +
                "      \"user_id\": 8487008\n" +
                "    },\n" +
                "    {\n" +
                "      \"creation_date\": \"2018-09-07 14:24:15\",\n" +
                "      \"document_id\": 137,\n" +
                "      \"file_name\": \"二代身份证反面\",\n" +
                "      \"front_document_id\": 69,\n" +
                "      \"url\": \"http://file11info.ppdai.com/***.jpg\",\n" +
                "      \"user_id\": 8487008\n" +
                "    },\n" +
                "    {\n" +
                "      \"creation_date\": \"2018-09-07 14:24:31\",\n" +
                "      \"document_id\": 137,\n" +
                "      \"file_name\": \"二代身份证反面\",\n" +
                "      \"front_document_id\": 69,\n" +
                "      \"url\": \"http://file11info.ppdai.com/***.jpg\",\n" +
                "      \"user_id\": 8487008\n" +
                "    },\n" +
                "    {\n" +
                "      \"creation_date\": \"2018-09-07 14:24:54\",\n" +
                "      \"document_id\": 138,\n" +
                "      \"file_name\": \"本人手持二代身份证的合照\",\n" +
                "      \"front_document_id\": 70,\n" +
                "      \"url\": \"http://file11info.ppdai.com/***.jpg\",\n" +
                "      \"user_id\": 8487008\n" +
                "    }\n" +
                "  ],\n" +
                "  \"msg\": \"success\",\n" +
                "  \"ret\": 0,\n" +
                "  \"serial_no\": \"747a095e-f80e-4879-a288-f75e1e4bd73b\"\n" +
                "}";
    }
}

猜你喜欢

转载自www.cnblogs.com/zhengwangzw/p/10877296.html