0

I may not have framed the query properly. So let me explain the problem I am facing.

Environment :
I have a server which responds to http API calls. The client making this call, is an html file on another server. So it is a cross domain call. The functionality is working as expected.

Problem :
On my webapp (tomcat servlet), I want to be able to get the domain name of the client, making this call

Example :
If http://abc.com/crossDomainCall.html is making the cross domain call to my server, I want to be able to see that it is abc.com

What I have tried :
I have tried request.getRemoteAddr() and request.getRemoveHost()
But they are returning the server address which was servicing the HTML at that point of time. Not the server address which is hosting the html (abc.com)

Any pointers on this, will be really appreciated.

Cheers,
Rohitesh

Edit 1 :
As @gigadot replied, using 'referer' from HTTP Header, is working for me. But this is not fool proof. So, my question is, how do services like Google Maps do this? I know, that they need to compare an API key, with the corresponding domain which has registered that key. So, how do they verify something like this?

2 Answers 2

1

Try to get referrer header in the request. That is your best bet since the actual call is made by the client side (user or web browser) so it is impossible to always get this. However, referrer header is not always sent by client web browser.

Sign up to request clarification or add additional context in comments.

2 Comments

This worked. I am getting the client domain. However, as you said, this is not foolproof. But what do the mashup service providers (like Google Maps) do, when they have to match an API key with the corresponding domain which registered that key?
I believe the API is a javascript snippet so they can use javascript to get the main url of the current web browser. But if it is just API for downloading JSON or XML, there is nothing they can do other than getting the referrer.
0

This is a cross-site ajax request, and it simply isn't possible.

Use $.getJSON() to retrieve your cross-site JSON response have you seen http://api.jquery.com/jQuery.getJSON.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.