简体   繁体   English

如何使用邮递员休息客户端将邮递请求发送到以下邮递方法

[英]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 + "]";
}

}
  1. Open Postman .打开Postman
  2. Enter URL in the URL bar http://{server:port}/json/metallica/post .在 URL 栏中输入 URL http://{server:port}/json/metallica/post
  3. Click Headers button and enter Content-Type as header and application/json in value.单击Headers按钮并输入Content-Type作为标题和application/json的值。
  4. Select POST from the dropdown next to the URL text box.从 URL 文本框旁边的下拉列表中选择POST
  5. Select raw from the buttons available below URL text box.从 URL 文本框下方的可用按钮中选择raw
  6. Select JSON from the following dropdown.从以下下拉列表中选择JSON
  7. In the textarea available below, post your request object:在下面可用的文本区域中,发布您的请求对象:

     { "title" : "test title", "singer" : "some singer" }
  8. Hit Send .点击Send

  9. 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

使用 POSTMAN POST 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正文 -> 表单数据

使用 POSTMAN POST multipart/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.

相关问题 如何使用邮递员休息客户端发送对象以调用REST服务,以便它将使用适当的方法参数命中以下给定的方法? - how to send object using postman rest client to call REST service so that it will hit the below given method with proper method parameters? 如何使用Postman从curl发布REST - How to Post a REST from curl using Postman 如何使用Java Rest客户端在POST负载中传递参数“ request”? - How to pass parameter 'request' in POST payload using Java Rest client? "如何使用 REST Assured 在正文中将请求作为 Json 数组发送以进行 Post" - How to send Request as Json Array in body for Post using REST Assured 如何使用java复制邮递员POST请求 - How to replicate Postman POST request using java 如何使用邮递员休息客户端发送对象以调用REST服务 - how to send object using postman rest client to call REST service 如何在 POST 请求中发送数组 rest 放心 - how to send an array in POST request rest assured 如何在POST方法的REST API中发送日期 - How to send Date in REST API in POST method 如何使用post方法在json数据中发送请求有效载荷 - how to send request payload in json data using post method 使用 WEBCLIENT 使用 POST 请求客户端方法 - to consume POST request client method using WEBCLIENT
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM