一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

ASP.NET XmlHttp跨域訪問實(shí)現(xiàn)代碼

原來由于瀏覽器的安全限制,網(wǎng)絡(luò)連接的跨域訪問時(shí)不被允許的。我們不能在瀏覽器端直接使用AJAX來跨域訪問資源,但是在服務(wù)器端是沒有這種跨域安全限制的。所以,我們只需要讓服務(wù)器端幫我們完成“跨域訪問”的工作,然后直接獲取服務(wù)器端“跨域訪問”的結(jié)果就可以了。分享下我的解決辦法,希望能有所幫助。^_^
CertCheck.ASPx: 
復(fù)制代碼 代碼如下:
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: 
復(fù)制代碼 代碼如下:
<?xml version="1.0"?>
<root>
</root>

PS: 在xh.send()中可以直接寫參數(shù),
CertCheck.ASPx:
復(fù)制代碼 代碼如下:
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
復(fù)制代碼 代碼如下:
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();
  }

AspNet技術(shù)ASP.NET XmlHttp跨域訪問實(shí)現(xiàn)代碼,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 日产精品一区二区免费 | www.日本一区 | 久久两性视频 | 一本色道久久综合亚洲精品高清 | 国产福利99 | 甘城光辉游乐园在线观看 | 激情影院成人区免费观看视频 | 一区二区视频在线免费观看 | 国产精彩视频在线观看 | 成人的天堂视频一区二区三区 | 在线亚洲小视频 | 国产一区二区高清在线 | 激情九九 | 最新毛片网站 | 国产一区自拍视频 | 天天天色综合 | 噜噜噜 综合 亚洲 | 国产高清精品自在线看 | 国产精品视屏 | 日韩a无v码在线播放免费 | 精品久久久一二三区 | 免费观看四虎精品国产永久 | 亚洲一区不卡 | 免费的成人a视频在线观看 免费的黄色片视频 | 国产乱子精品免费视观看片 | 视频一区二区在线播放 | 九九久久久久午夜精选 | 一级做α爰片久久毛片 | 国产午夜视频在线观看 | 四虎影永久在线观看精品 | 国产精品www夜色影视 | 337p欧美超大胆日本人术艺术 | 91网址免费入口 | 久久丝袜精品中文字幕 | 久久九九青青国产精品 | 欧美国产一区二区二区 | 看一级毛片国产一级毛片 | 亚洲视频一二区 | 欧美卡一卡二卡新区aaa | 巨胸喷奶水www久久久免费观看 | 中文字幕日韩理论在线 |