Java 如何使用邮递员休息客户端将邮递请求发送到以下邮递方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29364862/
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
How to send post request to the below post method using postman rest client
提问by user3962745
I just want to know, how to send JSON object to createTrackInJSON(Track track)
method, with @Post
annotation through postman rest client.
here,how to pass JSON object to createTrackInJSON(Track track) method,with @Post annotation ?
我只想知道,如何将 JSON 对象发送到createTrackInJSON(Track track)
方法,并@Post
通过邮递员休息客户端进行注释。在这里,如何使用 @Post 注释将 JSON 对象传递给 createTrackInJSON(Track track) 方法?
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.mkyong.Track;
@Path("/json/metallica")
public class JSONService {
@GET
@Path("/get")
@Produces(MediaType.APPLICATION_JSON)
public Track getTrackInJSON() {
Track track = new Track();
track.setTitle("Enter Sandman");
track.setSinger("Metallica");
System.out.println("inside get method . . .");
return track;
}
@POST
@Path("/post")
@Consumes(MediaType.APPLICATION_JSON)
public Response createTrackInJSON(Track track) {
System.out.println("inside post method . .");
String result = "Track saved : " + track;
return Response.status(201).entity(result).build();
}
}
//Track class is:
public class Track {
String title;
String singer;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getSinger() {
return singer;
}
public void setSinger(String singer) {
this.singer = singer;
}
@Override
public String toString() {
return "Track [title=" + title + ", singer=" + singer + "]";
}
}
采纳答案by Pramod Karandikar
- Open
Postman
. - Enter URL in the URL bar
http://{server:port}/json/metallica/post
. - Click
Headers
button and enterContent-Type
as header andapplication/json
in value. - Select
POST
from the dropdown next to the URL text box. - Select
raw
from the buttons available below URL text box. - Select
JSON
from the following dropdown. In the textarea available below, post your request object:
{ "title" : "test title", "singer" : "some singer" }
Hit
Send
.Refer to screenshot below:
- 打开
Postman
。 - 在 URL 栏中输入 URL
http://{server:port}/json/metallica/post
。 - 单击
Headers
按钮并输入Content-Type
标题和application/json
值。 POST
从 URL 文本框旁边的下拉列表中选择。- 选择
raw
从可用以下URL文本框中的按钮。 JSON
从以下下拉列表中选择。在下面可用的文本区域中,发布您的请求对象:
{ "title" : "test title", "singer" : "some singer" }
击中
Send
。请参考以下截图:
回答by Coder
The Interface of Postman is changing acccording to the updates.
Postman 的界面正在根据更新而变化。
So You can get full information about postman can get Here.
所以你可以在这里得到关于邮递员的完整信息。
回答by ganji
I had same issue . I passed my data as key->value in "Body" section by choosing "form-data" option and it worked fine.
我有同样的问题。我通过选择“表单数据”选项将我的数据作为“正文”部分中的键-> 值传递,并且它工作正常。
回答by jafarbtech
JSON:-
JSON:-
For POST request using json object it can be configured by selecting
对于使用 json 对象的 POST 请求,可以通过选择进行配置
Body -> raw -> application/json
正文 -> 原始 -> 应用程序/json
Form Data(For Normal content POST):-multipart/form-data
表单数据(对于普通内容 POST):-multipart/form-data
For normal POST request (using multipart/form-data) it can be configured by selecting
对于普通的 POST 请求(使用 multipart/form-data),可以通过选择进行配置
Body -> form-data
正文 -> 表单数据
回答by kishor kumar bc
1.Open postman app 2.Enter the URL in the URL bar in postman app along with the name of the design.Use slash(/) after URL to give the design name. 3.Select POST from the dropdown list from URL textbox. 4.Select raw from buttons available below the URL textbox. 5.Select JSON from the dropdown. 6.In the text area enter your data to be updated and enter send. 7.Select GET from dropdown list from URL textbox and enter send to see the updated result.
1.打开邮递员应用程序 2.在邮递员应用程序的 URL 栏中输入 URL 以及设计名称。在 URL 后使用斜杠 (/) 给出设计名称。3. 从 URL 文本框的下拉列表中选择 POST。4. 从 URL 文本框下方可用的按钮中选择原始。5. 从下拉列表中选择 JSON。6.在文本区域输入您要更新的数据并输入发送。7. 从 URL 文本框的下拉列表中选择 GET 并输入 send 以查看更新的结果。