开发者

get content of http request in REST web service using java

开发者 https://www.devze.com 2023-02-28 07:13 出处:网络
Anyone know how to get content of httprequest in REST webser开发者_JAVA百科vice using java? thanksYou can inject context about the individual requests. As an example, the code snippet below shows how

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

精彩评论

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