We know that Microsoft's xmldom/XMLHTTP component can be called by using JavaScript on the page to facilitate various remote resources on the page, such as webpage and XML data. However, due to the security restrictions of IE by default, we cannot access data sources in different domains through xmldom/XMLHTTP. In other words, www.sitea.com cannot access pages in www.siteb.com. We can use a simple local page proxy to implement this function. The new process will be: sitea.com/local.aspx (JavaScript)-> sitea.com/agent.aspx? Url = siteb.com/data.xml-> siteb.com/data.xml
Code It is very simple. The post method is supported, but other parameters in the URL are not processed at present in the get method. <% @ Page Language = " C # " Classname = " Pageagent " Validaterequest = " False " %>
<% @ Import namespace = " System. Io " %>
<% @ Import namespace = " System. net " %>
< Script Type = " Text/C # " Runat = " Server " >
Protected Override Void Onload (eventargs E)
{
Response. Clear ();
String URL = Request. querystring [ " URL " ];
If ( Null = URL | URL. Trim (). Length = 0 )
{
Response. End ();
Return;
}
Try
{
Webrequest request = Webrequest. Create (URL );
Request. Method = Request. requesttype;
Request. contenttype = Request. contenttype;
Int Reads = 0 ;
Byte [] Buffer = New Byte [ 512 ];
If (Request. requesttype. Equals ( " Post " , Stringcomparison. invariantcultureignorecase ))
{
If ( Null ! = Request. Form) {
Using (Stream s = Request. getrequeststream ())
{
While (Reads = Request. inputstream. Read (buffer, 0 , Buffer. Length )) > 0 )
{
S. Write (buffer,0, Reads );
}
S. Flush ();
}
}
}
Webresponse response = Request. getresponse ();
Response. contenttype = Response. contenttype;
Using (Stream s = Response. getresponsestream ())
{
While (Reads = S. Read (buffer, 0 , Buffer. Length )) > 0 )
{
Response. outputstream. Write (buffer,0, Reads );
}
}
Response. Close ();
}
Catch
{
}
Response. End ();
}
</ Script >