开发者

get content of http request in REST web service using java

Anyone know how to get content of httprequest in REST webser开发者_JAVA百科vice using java?

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.

@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.


Look at 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜