首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过火狐插件RESTClient更改GET-Request的内容类型

如何通过火狐插件RESTClient更改GET-Request的内容类型
EN

Stack Overflow用户
提问于 2013-07-31 15:23:46
回答 1查看 32K关注 0票数 5

我想发送GET-Requests,它将由我的REST-API应答。我的java程序员目前使用JAX-RS参考实现Jersey支持text/plaintext/htmltext/xmlapplication/json

为了测试不同的媒体类型,我使用了火狐插件RESTClient。为了改变媒体类型,我应该用name=Content-Typevalue=text/xml来调整报头。

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

我使用的是最新版本的RESTClient,现在是2.0.3。你能帮帮我吗?

下面是我的Java代码:

代码语言:javascript
复制
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);
  }

} 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-03 00:56:07

我认为除了声明请求的内容类型的content -Type头之外,还必须指定具有所需媒体类型的Accept头,而不是由Accept头设置的响应的内容类型

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

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17964088

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档