zoukankan      html  css  js  c++  java
  • .net后台通过xmlhttp 和远程服务通讯

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Net;
    namespace WebService1
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            //public static string result="";
            //public delegate int xmlhandle(myxmlhttp a,out string result);
            //public static event xmlhandle xmleventa;

            protected void Page_Load(object sender, EventArgs e)
            {
                MSXML2.XMLHTTPClass http = new MSXML2.XMLHTTPClass();
                try
                {
                    http.open("post", "http://localhost:2227/Default.aspx", false, "name", "psw");
                }
                catch
                {
                    Response.Write("远程服务连接不上");
                }
                http.send("ssssssss");

                if (http.readyState == 4)
                {
                    if (http.status == 200)
                    {
                        Response.Write(http.responseText);
                    }
                    else if (http.status == 401)
                    {
                        Response.Write("身份验证失败");
                    }
                    else
                    {
                        Response.Write("远程发生其他错误");
                    }
                }
                else
                {
                    Response.Write("未能完整接受数据");
                }
            }
        }
    }

    脚本可以通过onreadystatechange这个委托来调用方法。

    .net 中不行.因为onreadystatechange是只写的。当然可以继承xmlhttp,来覆写他的只写方法.加上一个事件.但是要实现所有接口.写起来麻烦。

    不知道上面的代码是否会有稳定性不好的地方。

  • 相关阅读:
    设计模式系列
    Python3 系列之 可变参数和关键字参数
    设计模式系列
    【HANA系列】SAP HANA ODBC error due to mismatch of version
    【FICO系列】SAP FICO FS00修改科目为未清项目管理
    【FIORI系列】SAP OpenUI5 (SAPUI5) js框架简单介绍
    【HANA系列】SAP HANA SQL获取当前日期加若干天后的日期
    【HANA系列】SAP HANA SQL获取本周的周一
    【HANA系列】SAP HANA SQL获取当前日期
    【HANA系列】SAP HANA SQL获取当前日期最后一天
  • 原文地址:https://www.cnblogs.com/lsfv/p/1496546.html
Copyright © 2011-2022 走看看