简体   繁体   English

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

[英]How to change Content-Type of GET-Request via firefox addon RESTClient

I want to send GET-Requests which shall be answered by my REST-API. 我想发送GET-Requests,我的REST-API将回答这些请求。 My java programm currently supports text/plain , text/html , text/xml and application/json using the JAX-RS Reference Implementation Jersey. 我的java程序目前支持使用JAX-RS Reference Implementation Jersey的text/plaintext/htmltext/xmlapplication/json

To test the different media types I'm using the firefox addon RESTClient . 要测试不同的媒体类型,我正在使用firefox插件RESTClient To change the media type I shall adjust the header with name=Content-Type and eg value=text/xml . 要更改媒体类型,我将使用name=Content-Type调整标题,例如value=text/xml

在此输入图像描述

But the RESTClient always returns text/html no matter which Content-Type I choose. 但无论我选择哪种Content-Type ,RESTClient都会返回text/html The only way right now to modify the returned result type is, to uncomment the html-section in my code. 现在修改返回结果类型的唯一方法是取消注释我的代码中的html-section。 Then text/plain will be the returned media type, but still the Content-Type argument of the RESTClient stays ignored. 然后text/plain将是返回的媒体类型,但仍然忽略RESTClient的Content-Type参数。

I'm using the most resent version of RESTClient, which is right now 2.0.3. 我正在使用RESTClient的最新版本,现在是2.0.3。 Can you please help me? 你能帮我么?

Here is my Java-Code: 这是我的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);
  }

} 

I think you have to specify the Accept header with the media type you want in addition to the Content-Type header that states what is the content type of your request, NOT the content type of the response which indeed is set by the Accept header 我认为你必须指定带有你想要的媒体类型的Accept标头,除了Content-Type标头,它说明了你的请求的内容类型,而不是确实由Accept标头设置的响应的内容类型。

So use the Accept header instead of Content-Type header 因此,请使用Accept标头而不是Content-Type标头

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 摆脱邮递员请求中的内容类型 - Get rid of Content-type in postman request GET请求标头中的内容类型 - Content-type in a GET request header 在PHP中获取请求的“Content-Type”标头 - Get “Content-Type” header of request in PHP 如何使用RESTclient Addon Firefox设置用于静态API身份验证的标头 - How to set header for restful api authentication using RESTclient Addon Firefox JSON REST Get-Request 正在等待 Chrome/Firefox Tomcat 上的 CORS - JSON REST Get-Request is pending with CORS on Tomcat for Chrome/Firefox 在.NET MVC 4(Web API)中,如何拦截控制器请求并更改其内容类型? - In .NET MVC 4 (Web API), how do I intercept a request for a controller and change it's Content-Type? 如何使用HttpClient在(HTTP GET)Rest请求头集合中添加&#39;Content-Type&#39;头? - how to add 'Content-Type' header in (HTTP GET) Rest request header collection using HttpClient? 设置 Content-Type 以从 Firefox 进行测试 - Set Content-Type for testing from Firefox 如何在此请求中添加Content-Type application / json - How to add Content-Type application/json in this request 如何为 HttpClient 请求设置 Content-Type header? - How do you set the Content-Type header for an HttpClient request?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM