问题
I am using Jeresy Jax-RS to build a web service. Now I need to get the url of the request with the port # if one exist.
So if my service runs on http://www.somelocation.com/web/services I want to capture the www.somelocation.com
How can I do this ?
回答1:
You can add a UriInfo parameter to your operation. From there you can access the URL:
@POST
@Consumes({"application/xml", "application/json"})
public Response create(@Context UriInfo uriInfo, Customer customer) {
...
}
来源:https://stackoverflow.com/questions/3834108/how-do-i-get-the-url-of-a-request