[英]How to send post request to the below post method using postman rest client
I just want to know, how to send JSON object to createTrackInJSON(Track track)
method, with @Post
annotation through postman rest client.我只想知道,如何通过邮递员休息客户端使用@Post
注释将 JSON 对象发送到createTrackInJSON(Track track)
方法。 here,how to pass JSON object to createTrackInJSON(Track track) method,with @Post annotation ?在这里,如何使用 @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 + "]";
}
}
Postman
.打开Postman
。http://{server:port}/json/metallica/post
.在 URL 栏中输入 URL http://{server:port}/json/metallica/post
。Headers
button and enter Content-Type
as header and application/json
in value.单击Headers
按钮并输入Content-Type
作为标题和application/json
的值。POST
from the dropdown next to the URL text box.从 URL 文本框旁边的下拉列表中选择POST
。raw
from the buttons available below URL text box.从 URL 文本框下方的可用按钮中选择raw
。JSON
from the following dropdown.从以下下拉列表中选择JSON
。In the textarea available below, post your request object:在下面可用的文本区域中,发布您的请求对象:
{ "title" : "test title", "singer" : "some singer" }
Hit Send
.点击Send
。
Refer to screenshot below:请参考以下截图:
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正文 -> 表单数据
The Interface of Postman is changing acccording to the updates. Postman 的界面正在根据更新而变化。
So You can get full information about postman can get Here.所以你可以得到关于邮递员的完整信息可以在这里得到。
https://www.getpostman.com/docs/requests https://www.getpostman.com/docs/requests
I had same issue .我有同样的问题。 I passed my data as key->value in "Body" section by choosing "form-data" option and it worked fine.我通过选择“表单数据”选项将我的数据作为“正文”部分中的键-> 值传递,并且它工作正常。
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. 1.打开邮递员应用程序 2.在邮递员应用程序的 URL 栏中输入 URL 以及设计名称。在 URL 后使用斜杠 (/) 给出设计名称。 3.Select POST from the dropdown list from URL textbox. 3. 从 URL 文本框的下拉列表中选择 POST。 4.Select raw from buttons available below the URL textbox. 4. 从 URL 文本框下方可用的按钮中选择原始。 5.Select JSON from the dropdown. 5. 从下拉列表中选择 JSON。 6.In the text area enter your data to be updated and enter send. 6.在文本区域输入您要更新的数据并输入发送。 7.Select GET from dropdown list from URL textbox and enter send to see the updated result. 7. 从 URL 文本框的下拉列表中选择 GET 并输入 send 以查看更新的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.