Web services 如何在URL中发布一些参数,在postman中发布一些参数作为json值

Web services 如何在URL中发布一些参数,在postman中发布一些参数作为json值,web-services,rest,jax-rs,postman,spring-restcontroller,Web Services,Rest,Jax Rs,Postman,Spring Restcontroller,我有一个post方法如下 @RequestMapping(value = "/user/profile", method = RequestMethod.POST) @ResponseBody public ResponseEntity<?> updateProfile(@RequestParam("userId") long userId, @RequestParam(value = "profilePicId", required = false) Long pr

我有一个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
}
我将其(json)发布在正文的原始部分下,格式为application/json。在标题部分下还输入了内容类型和字符集值

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


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

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

  • 使用正确的主机分配key
    host
    环境变量
  • 您可以从下拉方法列表中选择,
    POST
    method
  • 您的帖子正文位于选中的
    raw
    radiobutton下,格式为`JSON(application/JSON)
  • 您的JSON对象格式正确,请在上尝试

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

  • 使用正确的主机分配key
    host
    环境变量
  • 您可以从下拉方法列表中选择,
    POST
    method
  • 您的帖子正文位于选中的
    raw
    radiobutton下,格式为`JSON(application/JSON)
  • 您的JSON对象格式正确,请在上尝试

因为参数类型是@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作为参数传递。它在我的例子中起作用。

因为参数类型是@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作为参数传递。在我的情况下是有效的