ASP.NET XmlHttp跨域訪問實(shí)現(xiàn)代碼
CertCheck.aspx:
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:
<?xml version="1.0"?>
<root>
</root>
PS: 在xh.send()中可以直接寫參數(shù),
CertCheck.aspx:
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
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();
}
- AJAX javascript的跨域訪問執(zhí)行
- 解決AJAX中跨域訪問出現(xiàn)''沒有權(quán)限''的錯(cuò)誤
- asp.net Cookie跨域、虛擬目錄等設(shè)置方法
- JQuery Ajax 跨域訪問的解決方案
- asp.net(C#)跨域及跨域?qū)慍ookie問題
- ASP.NET MVC中EasyUI的datagrid跨域調(diào)用實(shí)現(xiàn)代碼
- asp.net關(guān)于Cookie跨域(域名)的問題
- AJAX的跨域訪問-兩種有效的解決方法介紹
- asp.net中WebResponse 跨域訪問實(shí)例代碼
- 支持Ajax跨域訪問ASP.NET Web Api 2(Cors)的示例教程
相關(guān)文章
asp.net 獲取Datalist中Checkbox的值的小結(jié)
最近開發(fā)過程中遇到一個(gè)小問題,要獲取checkbox的值,在網(wǎng)上搜索了一下,發(fā)現(xiàn)基本上都是用JS實(shí)現(xiàn)的,現(xiàn)在我將自己的做法記錄一下,以便以后繼續(xù)使用。2010-04-04asp.net 實(shí)現(xiàn)動(dòng)態(tài)顯示當(dāng)前時(shí)間(不用javascript不考慮開銷)
asp.net實(shí)現(xiàn)動(dòng)態(tài)顯示時(shí)間,無需用到j(luò)avascrip,而是用了AJAX。2009-11-11手動(dòng)把a(bǔ)sp.net的類生成dll文件的方法
當(dāng)我們在開發(fā)的時(shí)候,有時(shí)會將一些方法封裝起來供別人調(diào)用,下面就是一種生成DLL的方法.2009-11-11Asp.Net使用Npoi導(dǎo)入導(dǎo)出Excel的方法
這篇文章主要介紹了Asp.Net使用Npoi導(dǎo)入導(dǎo)出Excel的方法,采用該方法在導(dǎo)出Excel的時(shí)候不需要office組件的支持,而在導(dǎo)入Excel的時(shí)候采用OleDb的方式,需要office組件的支持。是一個(gè)非常實(shí)用的技巧,需要的朋友可以參考下2014-09-0912小時(shí)制和24小時(shí)制獲取當(dāng)天零點(diǎn)的問題探討
這篇文章介紹了12小時(shí)制和24小時(shí)制獲取當(dāng)天零點(diǎn)的問題探討,有需要的朋友可以參考一下2013-09-09asp.net用Zxing庫實(shí)現(xiàn)條形碼輸出的具體實(shí)現(xiàn)
這篇文章主要介紹了asp.net用Zxing庫實(shí)現(xiàn)條形碼輸出的具體實(shí)現(xiàn),有需要的朋友可以參考一下2013-12-12asp.net中利用ajax獲取動(dòng)態(tài)創(chuàng)建表中文本框的值
通常在做主從表的數(shù)據(jù)錄入中,會碰到在一個(gè)頁面上同時(shí)錄入主表數(shù)據(jù)和從表數(shù)據(jù),主表的數(shù)據(jù)只有一條,從表的數(shù)據(jù)有一條到多條,這樣就要?jiǎng)討B(tài)創(chuàng)建從表數(shù)據(jù)錄入入口。2010-03-03