Due to browser security restrictions, Cross-domain access to a network connection is not allowed. We cannot use Ajax directly on the browser side to access resources across domains, but there is no such cross-domain security restriction on the server side. So we just need to get the server side to help us with cross-domain access, and then get the results directly from the server-side Cross-domain access. Share my solution and hope it will help. ^_^
certcheck.aspx:
Copy Code code as follows:
Using MSXML2;
Namespace CA2
{
public partial class CertCheck:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
if (request["ResultId"]!= null)
{
string s = request["ResultId"];
String[] result = S.split (' @ ');
Label1.Text = result[1];
System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument ();
Xmldoc.load ("Vbr.xml");
System.Xml.XmlElement Regnode = xmldoc.createelement ("Id");
Regnode.innertext = result[0];
XmlDoc.DocumentElement.AppendChild (Regnode);
Regnode = Xmldoc.createelement ("Serial");
Regnode.innertext = result[1];
XmlDoc.DocumentElement.AppendChild (Regnode);
MSXML2. XMLHTTP XH = new MSXML2. Xmlhttpclass ();
Xh.open ("POST", "http://222.19.211.119/CAProcess.aspx", false, NULL, NULL);
Xh.setrequestheader ("Content-type", "Text/xml");
Xh.setrequestheader ("Content-type", "gb2312");
Xh.send (Xmldoc.innerxml);
if (xh.readystate = 4)
{
if (Xh.status = 200)
{
Label1.Text + = "###" + xh.responsetext;
}
}
}
}
}
}
Vbr.xml:
Copy Code code as follows:
<?xml version= "1.0"?>
<root>
</root>
PS: You can write parameters directly in Xh.send (),
Certcheck.aspx:
Copy Code code as follows:
Using System.Net;
Using System.IO;
Namespace CA2
{
public partial class CertCheck:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
if (request["ResultId"]!= null)
{
string s = request["ResultId"];
String[] result = S.split (' @ ');
Label1.Text = result[1];
string param = "id=" +result[0]+ "&serial=" +result[1];
byte[] bs = Encoding.ASCII.GetBytes (param);
HttpWebRequest req = (HttpWebRequest) httpwebrequest.create ("http://222.19.211.119/CAProcess.aspx");
Req. method = "POST";
Req. ContentType = "application/x-www-form-urlencoded";
Req. ContentLength = BS. Length;
Stream Reqstream = req. GetRequestStream ();
Reqstream.write (BS, 0, BS.) Length);
Reqstream.close ();
HttpWebResponse myresponse = (httpwebresponse) req. GetResponse ();
StreamReader reader = new StreamReader (Myresponse.getresponsestream (), encoding.getencoding ("GB2312"));
String content = Reader. ReadToEnd ();
Reader. Close ();
Myresponse.close ();
Label1.Text + + "###" + content. ToString ();
}
}
}
}
caprocess.aspx
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
int Id = Int. Parse (request.form["Id"]);
string serial = request.form["Serial"];
//
Response.Write (id.tostring () + "" +serial);
Response.End ();
}