rsapru
rsapru

Reputation: 698

How is this working?

I was browsing through one site called BSEINDIA.com (http://www.bseindia.com/stockreach/stockreach.htm?scripcd=532667), i Noticed that on click of Get Quote it seems to fire an Ajax request and get the price of selected equities. I tried to segregate this request and fire it separately, but it doesn't seem to work.

I copied over the code from the HTML of same page (http://www.bseindia.com/stockreach/stockreach.htm?scripcd=532667) Any pointers why is this not working, is there some sort of Authentication going on , i am not even a member of this site??

following is what i am trying to do

<script type="text/javascript">

var oHTTP=getHTTPObject();
var seconds = Math.random().toString(16).substring(2);

if(oHTTP)
{
    oHTTP.open("GET","http://www.bseindia.com/DotNetStockReachs/DetailedStockReach.aspx?GUID="+seconds+"&scripcd=532667",true);
    oHTTP.onreadystatechange=AJAXRes;
    oHTTP.send(null);
}

function AJAXRes()
{
    if(oHTTP.readyState==4)alert(oHTTP.responseText);
}

function getHTTPObject(){var obj;
try{obj=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e){try{
obj=new ActiveXObject("Microsoft.XMLHTTP");}
catch(e1){obj=null;}}
if(!obj&& typeof XMLHttpRequest!='undefined'){
try{obj=new XMLHttpRequest();}
catch(e){obj=false;}}return obj;}



</script>

Found out my Answer here http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.referer%28VS.71%29.aspx

Upvotes: 0

Views: 271

Answers (3)

Andrew Moore
Andrew Moore

Reputation: 95444

Actually, it is fairly easy. When you send an HTTP request, an header called Referrer gets sent with the request. The Referrer is basically the URL of the page which initiated the request.

BSEINDIA checks the Referrer value to make sure that the request is coming from their site. If it is, it sends the data. If not, it sends its 404 page.

You can easily test that theory by disabling the Referrer in your browser. In Firefox, you can do that by typing about:config and setting network.http.sendRefererHeader to 0.

If you still want to get the data, you will need to write a script (in PHP or another language) which will make the request with the proper Referrer and output the results.

Upvotes: 2

Marius Seritan
Marius Seritan

Reputation: 157

Possibly Http Referrer. Make sure you do not break any copyright restriction.

Upvotes: 0

Christian
Christian

Reputation: 3988

There might be some form of IP restriction in place for accessing the files / data needed to save themselves from third party scripts accessing their data through their own scripts. Thats what I'd do.

Upvotes: 0

Related Questions