【问题标题】:How to post some parameter in URL and some parameters as json value in postman如何在 URL 中发布一些参数,在邮递员中将一些参数作为 json 值发布
【发布时间】:2016-11-18 13:48:07
【问题描述】:

我有一个post方法如下

@RequestMapping(value = "/user/profile", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<?> updateProfile(@RequestParam("userId") long userId,
        @RequestParam(value = "profilePicId", required = false) Long profilePicId,
        @RequestParam("payload") String payload) throws IOException {
//some logic
}

我想通过邮递员打,这是我的请求网址 {{host}}/abc/api/someVersion/user/profile/?userId=12345 其中 userId 是请求参数,json 作为另一个参数(即有效负载)

{
"showInitials": true,
"personalQuote": "",
"wooAlbum": [{
    "photoStatus": "APPROVED",
    "objectId": "1509974142644942",
    "imageOrder": 0,
    "srcBig": "http:\/\/amazonaws.com\/uploadedPhoto\/1472267515843.jpeg",
    "profilePic": true
}, {
    "photoStatus": "APPROVED",
    "objectId": "1509970579311965",
    "imageOrder": 1,
    "srcBig": "http:\/\/amazonaws.com\/wooPictures\/1234.jpg",
    "profilePic": false
}],
"degree": [{
    "isSelected": 1,
    "tagId": 1,
    "tagsDtoType": "NONE",
    "name": "No Info (update your linked account)"
}],
"company": [{
    "isSelected": 0,
    "tagId": 1,
    "tagsDtoType": "NONE",
    "name": "No Info (update your linked account)"
}],
"college": [{
    "isSelected": 1,
    "tagId": 169421983068086,
    "tagsDtoType": "USER_EDUCATION",
    "name": "MDU, Rohtak"
}],
"religion": [],
"location": " Delhi",
"showHeightType": "INCHES",
"ethnicity": [],
"isMutualFriendVisible": false,
"tagsDtos": [{
    "tagId": "12",
    "name": "Tennis",
    "tagsDtoType": "WOO_TAG"
}, {
    "tagId": "16",
    "name": "Marathons Runner",
    "tagsDtoType": "WOO_TAG"
}, {
    "tagId": "19",
    "name": "Basket ball",
    "tagsDtoType": "WOO_TAG"
}],
"designation": [{
    "isSelected": 0,
    "tagId": 1,
    "tagsDtoType": "NONE",
    "name": "No Info (update your linked account)"
}]}

我在正文的原始部分下发布了它(json),而格式是 application/json。还在标题部分下输入了内容类型和字符集值。

点击发送按钮后,我收到 400(Bad Request) 作为响应。

谁能建议如何为这些参数创建 url?

【问题讨论】:

    标签: web-services rest jax-rs postman spring-restcontroller


    【解决方案1】:

    您确保您的邮递员选项符合您的用例要求,因此请检查:

    • 您将密钥 host 的环境变量分配给正确的主机。
    • 您从下拉方法列表中选择POST 方法。
    • 您的帖子正文位于 raw 选中的单选按钮下,并格式化为 `JSON (application/json)
    • 您的 JSON 对象格式正确,请在 jsonformatter.curiousconcept.com 上试一试

    【讨论】:

      【解决方案2】:

      由于参数类型是@RequestParam,因此我使用url(不在正文中)传递了有效负载并且它起作用了。这是完整的请求网址

      {{host}}/abc/api/someVersion/user/profile/?userId=12345&payload={"showInitials":true,"personalQuote":"abc","wooAlbum":[{"photoStatus":"APPROVED","objectId":"1509974142644942","imageOrder":0,"srcBig":"http:\/\/u2-woostore.s3.amazonaws.com\/uploadedPhoto\/1472267517964_4193248.1472267515843.jpeg","profilePic":true},{"photoStatus":"APPROVED","objectId":"1509970579311965","imageOrder":1,"srcBig":"http:\/\/u2-woostore.s3.amazonaws.com\/wooPictures\/1509970579311965.jpg","profilePic":false}],"degree":[{"isSelected":1,"tagId":1,"tagsDtoType":"NONE","name":"No Info (update your linked account)"}],"company":[{"isSelected":0,"tagId":1,"tagsDtoType":"NONE","name":"No Info (update your linked account)"}],"college":[{"isSelected":1,"tagId":169421983068086,"tagsDtoType":"USER_EDUCATION","name":"MDU, Rohtak"}],"religion":[],"location":" Delhi","showHeightType":"INCHES","ethnicity":[],"isMutualFriendVisible":false,"tagsDtos":[{"tagId":"12","name":"Tennis","tagsDtoType":"WOO_TAG"},{"tagId":"16","name":"Marathons Runner","tagsDtoType":"WOO_TAG"},{"tagId":"19","name":"Basket ball","tagsDtoType":"WOO_TAG"}],"designation":[{"isSelected":0,"tagId":1,"tagsDtoType":"NONE","name":"No Info (update your linked account)"}]}
      

      在 url 中传递完整的有效 json 作为参数。它在我的情况下有效。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-09
        • 2016-09-08
        • 1970-01-01
        • 1970-01-01
        • 2019-01-10
        • 1970-01-01
        • 2021-03-12
        • 1970-01-01
        相关资源
        最近更新 更多