asp.net xmlhttp post XML

來源:互聯網
上載者:User
 

 asp.net   xmlhttp   post XML

 

XmlDocument   xmldoc   =   new   XmlDocument();  
  xmldoc.Load(Request.InputStream);  
  string   RootFolder=xmldoc.ChildNodes[0].InnerText;

 

 

Asp.net XMLHTTP 基類 (GET,Post發送和接收資料)Submitted by 浪淘沙 on 2007, June 21, 2:50 PM. asp.net

/############################################
著作權聲明:
文章內容為本站編輯,創作.你可以任意轉載、發布、使用但請務必以明文標註文章原始出處及本聲明
http://www.opent.cn  作者:浪淘沙
############################################/

/****************************************************************
 * 函數名稱:SendCommand(SendMethod method, ST_Param p)
 * 功能說明:向遠程發送URL和參數,接受返回資訊(無亂碼);
 * 參    數:method:xml發送方法,POST/Get 兩種
      P:參數結構體
              public string Url; //遠程URL
              public string Parameters; //參數
              public string Uid; //帳號
              public string Pwd; //號令
 * 調用示列:
 *           using ebcnc;    //引用空間名
 *           XMLHTTP x = new XMLHTTP(); //建立設xmlhttp對像
 *           XMLHTTP.ST_Param st = new XMLHTTP.ST_Param(); //建立參數數組
 *           st.Parameters = "";  //url詳細參數
 *           st.Url = "http://www.baidu.com"; //url
 *           st.Uid = ""  ; //帳號
 *           st.Pwd = ""; //口令
 *           string rn=””; //返回字串
 *           rn=x.SendCommand(XMLHTTP.SendMethod.POST, st); //擷取返回資訊
 *           x.Dispose();

***********************************************************************/
using System;
using MSXML2;
namespace ebcnc
{
    /// <summary>
    /// XMLHTTP基類
    /// </summary>
    public class XMLHTTP : IDisposable
    {
        #region 變數及參數
        private XMLHTTPClass xml;
        private bool _alreadyDispose = false;

        public ST_Param Parameters;

        public enum SendMethod : int
        {
            POST, GET
        }
        #endregion

        #region 參數結構體
        public struct ST_Param
        {
            public string Url;
            public string Parameters;
            public string Uid;
            public string Pwd;
        }
        #endregion

        #region 發送資料
        /// <summary>
        /// 發送資料
        /// </summary>
        /// <param name="method">發送方式</param>
        /// <param name="p">資料</param>
        /// <returns>STRING</returns>
        public virtual string SendCommand(SendMethod method, ST_Param p)
        {
            if (p.Url == null || p.Url == "") return null;
            if (method == SendMethod.POST)
            {
                try
                {
                    xml.open("POST", p.Url, false, p.Uid, p.Pwd);
                    xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                    xml.send(CommonFunction.UrlEncoding(p.Parameters));
                    if (xml.status == 200)
                    {
                        return System.Text.Encoding.Default.GetString((byte[])xml.responseBody);
                    }
                    else
                    {
                        return xml.status.ToString();
                    }
                }
                catch (Exception E)
                {
                    return E.Message.ToString();
                }
            }
            else if (method == SendMethod.GET)
            {
                xml.open("GET", p.Url + "?" + CommonFunction.UrlEncoding(p.Parameters), false, p.Uid, p.Pwd);
                xml.send(null);
                return System.Text.Encoding.Default.GetString((byte[])xml.responseBody);
            }
            return null;
        }
        #endregion

        #region 構造與釋構
        public XMLHTTP()
        {
            xml = new XMLHTTPClass();
        }
        ~XMLHTTP()
        {
            Dispose();
        }
        protected virtual void Dispose(bool isDisposing)
        {
            if (_alreadyDispose) return;
            if (isDisposing)
            {
                if (xml != null)
                {
                    xml = null;
                }
            }
            _alreadyDispose = true;
        }
        #endregion

        #region IDisposable 成員

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        #endregion
    }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.