当前位置:编程学习 > C#/ASP.NET >>

C# HttpWebRequest通用类(一)

/*

使用方法:
MyHttp loHttp = new MyHttp();
string lcHtml = "";

loHttp.HandleCookies = true;//操作Cookies
loHttp.Method = "GET";
lcHtml = loHttp.GetUrl("http://signin.ebay.com.cn/ws2/eBayISAPI.dll?SignIn&ssPageName=h:h:sout:CN");

loHttp.AddPostKey("Key", "Value");
loHttp.Referer = "http://signin.ebay.com.cn/ws2/eBayISAPI.dll?SignIn&ssPageName=h:h:sout:CN";

loHttp.Method = "POST";
lcHtml = loHttp.GetUrl("http://signin.ebay.com.cn/ws2/eBayISAPI.dll");

MessageBox.Show(loHttp.ErrorMsg);
MessageBox.Show(lcHtml);

*/

using System;
using System.Collections;
using System.Text;
using System.Web;
using System.Windows.Forms;//only For Use MessageBox
using System.Net;
using System.IO;
using System.Diagnostics;

namespace HttpWeb
{
    public class MyHttp
    {
        /// <summary>
        /// User name used for Authentication.
        /// To use the currently logged in user when accessing an NTLM resource you can use "AUTOLOGIN".
        /// </summary>
        public string Username
        {
            get { return this.cUsername; }
            set { cUsername = value; }
        }

        /// <summary>
        /// Password for Authentication.
        /// </summary>
        public string Password
        {
            get { return this.cPassword; }
            set { this.cPassword = value; }
        }

        /// <summary>
        /// Address of the Proxy Server to be used.
        /// Use optional DEFAULTPROXY value to specify that you want to IE's Proxy Settings
        /// </summary>
        public string ProxyAddress
        {
            get { return this.cProxyAddress; }
            set { this.cProxyAddress = value; }
        }

        /// <summary>
        /// Semicolon separated Address list of the servers the proxy is not used for.
        /// </summary>
        public string ProxyBypass
        {
            get { return this.cProxyBypass; }
            set { this.cProxyBypass = value; }
        }

        /// <summary>
        /// Username for a password validating Proxy. Only used if the proxy info is set.
        /// </summary>
        public string ProxyUsername
        {
            get { return this.cProxyUsername; }
            set { this.cProxyUsername = value; }
        }
        /// <summary>
        /// Password for a password validating Proxy. Only used if the proxy info is set.
        /// </summary>
        public string ProxyPassword
        {
            get { return this.cProxyPassword; }
            set { this.cProxyPassword = value; }
        }

        /// <summary>
        /// Timeout for the Web request in seconds. Times out on connection, read and send operations.
        /// Default is 30 seconds.
        /// </summary>
        public int Timeout
        {
            get { return this.nConnectTimeout; }
            set { this.nConnectTimeout = value; }
        }

 

        public bool HandleReferer
        {
            get { return this.bHandleReferer; }
            set { this.bHandleReferer = value; }
        }

        /// <summary>
        /// 引用页
        /// </summary>
        public string Referer
        {
            get { return this.cReferer; }
            set { this.cReferer = value; }
        }

        /// <summary>
        /// 提交模式,默认是POST,用GET模式的时候不能使用PostData
        /// </summary>
        /// <value></value>
        public string Method
        {
            get { return this.cMethod; }
            set { this.cMethod = value; }
        }
        /// <summary>
        /// Error Message if the Error Flag is set or an error value is returned from a method.
        ///

补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,