简体   繁体   English

使用Java在REST Web服务中获取http请求的内容

[英]get content of http request in REST web service using java

Anyone know how to get content of httprequest in REST webservice using java? 有谁知道如何使用Java在REST Web服务中获取httprequest的内容?

thanks 谢谢

You can inject context about the individual requests. 您可以插入有关单个请求的上下文。 As an example, the code snippet below shows how the HTTP request headers can be injected. 例如,下面的代码片段显示了如何注入HTTP请求标头。

@GET  
@Produces{"text/plain"}  
public String listHeaderNames(@Context HttpHeaders headers) {  
  StringBuilder buf = new StringBuilder();  
  for (String header: headers.getRequestHeaders().keySet()) {  
    buf.append(header);  
    buf.append("\n");  
  }  
  return buf.toString();  
}

See the relevant part of the JAX-RS 1.1 specification for more information. 有关更多信息,请参见JAX-RS 1.1规范的相关部分

Look at Restlet Restlet

// Create the client resource  
ClientResource resource = new ClientResource("http://www.restlet.org");  

// Write the response entity on the console
resource.get().write(System.out);

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM