Java 邮递员 REST 客户端原始 json 数据如何在 POST、PUT 调用中发送到服务器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18738820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 10:36:47  来源:igfitidea点击:

how postman REST Client raw json data is sent to server in POST, PUT calls?

javarestposthttp-headershttp-post

提问by ram

I'm working on a application to test API calls, in which i'm able to generate URL for paramaters which is declared with annotation @Requestparamand @Pathvariable.

我正在开发一个应用程序来测试 API 调用,在其中我能够为使用注释@Requestparam@Pathvariable声明的参数生成 URL 。

But when using @RequestBodywe use rawin post man. I'm not sure how data is sent in raw. I just want to know how to send data in rawto server.

但是当使用@RequestBody 时,我们在邮递员中使用raw。我不确定如何以原始数据发送数据。我只想知道如何将原始数据发送到服务器。

Any help is appreciated. Thanks in Advance.

任何帮助表示赞赏。提前致谢。

I'm doing this as AJAX using Jquery.

我正在使用 Jquery 作为 AJAX 执行此操作。

回答by Abhinav

You just need to set the 'data' attribute in the $.ajax call as shown here: http://api.jquery.com/jQuery.ajax/.

您只需要在 $.ajax 调用中设置 'data' 属性,如下所示:http: //api.jquery.com/jQuery.ajax/

回答by Aravind

Your Request body should be like below when you use raw:

当您使用 raw 时,您的请求正文应如下所示:

{"param1":"value1","param2":"value2","param3":"value3","param4":"value4"}

回答by Ema.H

In the headeroption of the request, add Content-Type:application/json
header content-type postman json

在请求的header选项中,添加Content-Type:application/json
标题内容类型邮递员 json

and in the body, select Rawformat and put your json params like {'guid':'61791957-81A3-4264-8F32-49BCFB4544D8'}

并在正文中,选择原始格式并将您的 json 参数设置为{'guid':'61791957-81A3-4264-8F32-49BCFB4544D8'}

body postman json

身体邮递员json

I've found the solution on http://www.iminfo.in/post/post-json-postman-rest-client-chrome

我在http://www.iminfo.in/post/post-json-postman-rest-client-chrome上找到了解决方案

回答by Deepu

In addition to the below comments, make sure the formatting is right as well.

除了以下注释之外,还要确保格式正确。

{
 "param1" : "value1",
 "param2": "value2"
}

回答by Rajpurohit Dhanpal Singh

Use a double quote for variable and separate it with comma.

对变量使用双引号并用逗号分隔。

example :

例子 :

{ "id" :"1", "name":"xyz" }

{ "id":"1", "name":"xyz" }