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 ?
A request URL consists of an HTTP method, a base URL, and a resource URI. The request header also includes parameters such as the content type and authorization information.
API URL. The API is accessed from the URL: http://www.domain.com/api/index.php.
To use the url we need to import the o package called net/url. We can pass the url as the argument to the functions of the url. For example, if we have an url and we want to check the port of the given url by calling the function of the url like Port() where u =url. Parse(“www.xyz.com”).
The GET request consists of the request-line and HTTP headers section. The GET request-line begins with an HTTP method token, followed by the request URI and the protocol version, ending with CRLF. Space characters separate the elements. Below is an example of a GET request to the ReqBin echo server.
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) {
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With