如何使用邮递员休息客户端将帖子请求发送到以下帖子方法 [英] How to send post request to the below post method using postman rest client

查看:143
本文介绍了如何使用邮递员休息客户端将帖子请求发送到以下帖子方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道,如何使用 @Post createTrackInJSON(Track track)方法>通过邮递员休息客户注释。
这里,如何通过@Post注释将JSON对象传递给createTrackInJSON(Track track)方法?

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 ?

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. 打开邮递员

  2. 在网址栏中输入网址 http :// {server:port} / json / metallica / post

  3. 点击标题按钮输入 Content-Type 作为标题,输入 application / json

  4. 从URL文本框旁边的下拉列表中选择 POST

  5. 选择 raw 从URL文本框下方的按钮开始。

  6. 从以下下拉菜单中选择 JSON

  7. 在下面提供的textarea中,发布您的请求对象:

  1. Open Postman.
  2. Enter URL in the URL bar http://{server:port}/json/metallica/post.
  3. Click Headers button and enter Content-Type as header and application/json in value.
  4. Select POST from the dropdown next to the URL text box.
  5. Select raw from the buttons available below URL text box.
  6. Select JSON from the following dropdown.
  7. In the textarea available below, post your request object:

{
 "title" : "test title",
 "singer" : "some singer"
}


  • 点击发送

    请参阅下面的截图:

    Refer to screenshot below:

    这篇关于如何使用邮递员休息客户端将帖子请求发送到以下帖子方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆