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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 07:51:34  来源:igfitidea点击:

How to send post request to the below post method using postman rest client

javaweb-servicesrest

提问by user3962745

I just want to know, how to send JSON object to createTrackInJSON(Track track)method, with @Postannotation 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

  1. Open Postman.
  2. Enter URL in the URL bar http://{server:port}/json/metallica/post.
  3. Click Headersbutton and enter Content-Typeas header and application/jsonin value.
  4. Select POSTfrom the dropdown next to the URL text box.
  5. Select rawfrom the buttons available below URL text box.
  6. Select JSONfrom the following dropdown.
  7. In the textarea available below, post your request object:

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

  9. Refer to screenshot below: enter image description here

  1. 打开Postman
  2. 在 URL 栏中输入 URL http://{server:port}/json/metallica/post
  3. 单击Headers按钮并输入Content-Type标题和application/json值。
  4. POST从 URL 文本框旁边的下拉列表中选择。
  5. 选择raw从可用以下URL文本框中的按钮。
  6. JSON从以下下拉列表中选择。
  7. 在下面可用的文本区域中,发布您的请求对象:

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

  9. 请参考以下截图: 在此处输入图片说明

回答by Coder

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

回答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

POST JSON object using POSTMAN

使用 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

正文 -> 表单数据

POST multipart/form-data using POSTMAN

使用 POSTMAN POST multipart/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 以查看更新的结果。