Currently I am working with Rest API(Spring MVC). UI Part is developed in Angular JS. this project will integrate any of the domain.
For example : www.xyz.com containing my register button www.abc.com also may contain my register button.
When the request I received from user, I need to find out that, from which domain the request is coming?
Tried with the following:
@GET
@Path("/gethostname")
@Produces("application/json")
public void test(@Context HttpHeaders httpHeaders, @RequestBody JSONObject inputObj) {
System.out.println("=========> "+httpHeaders.getHeaderString("host"));
}
But it return REST API(server) Host name. How can I get client host name?
There are two ways for you to get hostname
By calling below code on server side, please note that this will come as null if url is directly entered in browser.
String referrer = request.getHeader("referer");
Check this image
Or you can provide below code to be added on client side and on server you can read the value of domain
which will return hostname
<input type="button" value="Register" onClick="call()"/>
<script>
function call(){
var domain=window.location.hostname;
window.open('http://<your-hostname>/register?domain='+domain,'_self');
}
</script>
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