示例#1
0
        public static void PutFile(string url, HttpPara para, string file)
        {
            HttpWebRequest request = HttpWebUtility.Create(url, para, "PUT", null);

            HttpWebUtility.SentFile(request, file);
            HttpWebUtility.Receive(request);
        }
示例#2
0
        public static void PutImage(string url, HttpPara para, Image image)
        {
            HttpWebRequest request = HttpWebUtility.Create(url, para, "PUT", null);

            HttpWebUtility.SentImage(request, image);
            HttpWebUtility.Receive(request);
        }
示例#3
0
        public static void PutText(string url, HttpPara para, string text)
        {
            HttpWebRequest request = HttpWebUtility.Create(url, para, "PUT", null);

            HttpWebUtility.SentText(request, text);
            HttpWebUtility.Receive(request);
        }
示例#4
0
        public static string Post(string url, HttpPara para, string text = null)
        {
            HttpWebRequest request = HttpWebUtility.Create(url, para, "POST", "application/x-www-form-urlencoded");

            if (text != null)
            {
                HttpWebUtility.SentText(request, text);
            }
            return(HttpWebUtility.ReceiveString(request));
        }
示例#5
0
        internal static HttpWebRequest Create(string url, HttpPara httpPara, string httpMethod, string contentType)
        {
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException(nameof(url));
            }

            SetSecurityProtocol(url);
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

            request.Method    = httpMethod;
            request.UserAgent = DEFAULT_USER_AGENT;

            if (httpPara.Timeout != default)
            {
                request.Timeout = httpPara.Timeout;
            }

            if (httpPara.AuthHeader != null)
            {
                request.Headers.Add(httpPara.AuthHeader);
            }

            if (!string.IsNullOrEmpty(contentType))
            {
                request.ContentType = contentType;
            }

            request.CookieContainer = new CookieContainer();
            if (httpPara.Cookies != null)
            {
                request.CookieContainer.Add(httpPara.Cookies);
            }

            return(request);
        }
示例#6
0
        public static CookieCollection GetCookie(string url, HttpPara para)
        {
            HttpWebRequest request = HttpWebUtility.Create(url, para, "HEAD", null);

            return(HttpWebUtility.ReceiveCookie(request));
        }
示例#7
0
        public static string Operate(string url, HttpPara para, string method)
        {
            HttpWebRequest request = HttpWebUtility.Create(url, para, method, null);

            return(HttpWebUtility.ReceiveString(request));
        }
示例#8
0
        public static void GetFile(string url, HttpPara para, string savePath)
        {
            HttpWebRequest request = HttpWebUtility.Create(url, para, "GET", null);

            HttpWebUtility.ReceiveFile(request, savePath);
        }
示例#9
0
        public static string GetText(string url, HttpPara para)
        {
            HttpWebRequest request = HttpWebUtility.Create(url, para, "GET", null);

            return(HttpWebUtility.ReceiveString(request));
        }