如何在postman中发布URL中的一些参数和一些参数作为json值

时间:2016-11-16 12:17:44

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

我有一个post方法如下

<Application.Resources>
    <ResourceDictionary>
        <Style TargetType="Button">
            <Setter Property="TextColor" Value="White" />
            <Setter Property="BackgroundColor" Value="Blue" />
        </Style>
    </ResourceDictionary>
</Application.Resources>

我想通过邮递员点击它,这是我的请求网址 @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 } 其中userId是请求参数,json是另一个参数(即有效载荷)

{{host}}/abc/api/someVersion/user/profile/?userId=12345

我在身体的原始部分下贴了它(json),而格式是application / json。还在标题部分下输入了content-type和charset值。

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

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

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

由于参数类型是@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作为参数传递。它适用于我的情况。