如何通过firefox插件RESTClient更改GET-Request的Content-Type

Mar*_*kus 5 rest content-type jersey media-type rest-client

我想发送GET-Requests,我的REST-API将回答这些请求.我的Java PROGRAMM目前支持text/plain,text/html,text/xmlapplication/json使用JAX-RS参考实现新泽西州.

要测试不同的媒体类型我正在使用firefox插件RESTClient.要更改媒体类型,我将使用name=Content-Type和例如调整标题value=text/xml.

在此输入图像描述

text/html无论Content-Type我选择哪种方式,RESTClient总会返回.现在修改返回结果类型的唯一方法是取消注释我的代码中的html-section.然后text/plain将是返回的媒体类型,但仍然Content-Type忽略RESTClient 的参数.

我正在使用RESTClient的最新版本,现在是2.0.3.你能帮我么?

这是我的Java代码:

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

//Sets the path to base URL + /hello
@Path("/hello")
public class restProvider {

  // This method is called if TEXT_PLAIN is request
  @GET
  @Produces(MediaType.TEXT_PLAIN)
  public String sayPlainTextHello() {
    return "Hello little World";
  }

  // This method is called if XML is request
  @GET
  @Produces(MediaType.TEXT_XML)
  public String sayXMLHello() {
    return "<?xml version=\"1.0\"?>" + "<hello> Hello little World" + "</hello>";
  }

  // This method is called if HTML is request
  // Uncommenting the following 6 lines will result in returning text/plain
  @GET
  @Produces(MediaType.TEXT_HTML)
  public String sayHtmlHello() {
    return "<html> " + "<title>" + "Hello World" + "</title>"
        + "<body><h1>" + "Hello little World" + "</h1></body>" + "</html> ";
  }

  // This method is called if JSON is requested
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  public String getJson(){
      Gson gsonObject = new Gson();
      return gsonObject.toJson(helloClass);
  }

} 
Run Code Online (Sandbox Code Playgroud)

fut*_*ics 10

我认为你必须指定Accept你想要的媒体类型的标题,除了Content-Type标题,它指出你的请求的内容类型,而不是Accept标题确定的响应的内容类型

因此,请使用Accept标头而不是Content-Type标头