views:

140

answers:

3

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+"&amp;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

A: 

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.

Christian
An AJAX request firing from your browser would have your IP as the origination, wouldn't it?
thedz
Of course it would, but what about the server-side files on the other end?
Christian
A: 

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

Marius Seritan
+2  A: 

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.

Andrew Moore
Maybe worth trying this extension in FF to spoof the referer https://addons.mozilla.org/en-US/firefox/addon/4513
Osseta
Perfect, but does that mean that i cant kind of automate this :(
rsapru
Thanks, I found out way to do it http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.referer%28VS.71%29.aspx
rsapru