如何 post URL 中的某些参数和 post 中的某些参数作为 json 值

How to post some parameter in URL and some parameters as json value in postman

我有一个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
}

我想通过post人来打,这是我的要求URL {{host}}/abc/api/someVersion/user/profile/?userId=12345 其中 userId 是请求参数,json 作为另一个参数(即 payload)

{
"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)"
}]}

我在 body 的原始部分下 post 编辑了它 (json),而格式是 application/json。还在 header 部分下输入了 content-type 和字符集值。

点击发送按钮后,我收到 400(错误请求)作为响应。

有人可以建议如何为这些参数创建 url 吗?

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

  • 您为正确的主机分配了密钥 host 的环境变量。
  • 您从下拉方法列表中选择,POST 方法。
  • 您的 post 正文在 raw 单选按钮下被选中,格式为 `JSON (application/json)
  • 您的 JSON 对象格式正确,请尝试 jsonformatter.curiousconcept.com

由于参数类型是@RequestParam,因此我使用url(不在正文中)传递了有效负载并且它起作用了。这是完整的请求 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 作为参数传递。它适用于我的情况。