Esempio n. 1
0
        /// <summary>
        /// Post 请求
        /// </summary>
        /// <param name="requestInfo"></param>
        /// <returns></returns>
        public static ResponeInfo Post(RequestInfo requestInfo)
        {
            var httpcode = 200;

            string outcookieheader;
            var    url          = requestInfo.Url;
            var    querystrings = requestInfo.QueryParams.Select(x => x.Key + "=" + x.Value);
            var    querys       = string.Join("&", querystrings);
            var    responeText  = Http.PostUrl(url, querys, requestInfo.Cookieheader, out outcookieheader,
                                               requestInfo.HeaderReferer, requestInfo.AutoRedirect, requestInfo.HeaderUserAgent, requestInfo.HttpType,
                                               requestInfo.Encoding, requestInfo.Timeout, requestInfo.Mywebproxy, requestInfo.NetworkCredentialName,
                                               requestInfo.NetworkCredentialPassword, requestInfo.HttpExpect100Continue,
                                               requestInfo.ServicePointManagerExpect100Continue,
                                               requestInfo.Headers.Select(x => x.Key + ":" + x.Value).ToArray());
            var respone = new ResponeInfo
            {
                HttpCodeState   = httpcode,
                Outcookieheader = outcookieheader,
                ResponeText     = responeText
            };

            return(respone);
        }
Esempio n. 2
0
        /// <summary>
        /// GET 请求
        /// </summary>
        /// <param name="requestInfo"></param>
        /// <param name="credentials"></param>
        /// <returns></returns>
        public static ResponeInfo Get(RequestInfo requestInfo)
        {
            string outcookieheader;
            var    httpcode = 200;

            var querystrings = requestInfo.QueryParams.Select(x => x.Key + "=" + x.Value);
            var querys       = string.Join("&", querystrings);

            var url = requestInfo.Url;

            url = url.TrimEnd('?', '&');

            if (url.IndexOf("?", StringComparison.Ordinal) < 0)
            {
                url += "?" + querys;
            }
            else
            {
                url += "&" + querys;
            }

            var text = Http.GetUrl(url, requestInfo.Cookieheader, out outcookieheader, requestInfo.HeaderReferer,
                                   requestInfo.AutoRedirect, requestInfo.HeaderUserAgent, requestInfo.HttpType, requestInfo.Encoding,
                                   requestInfo.Timeout, requestInfo.Mywebproxy, requestInfo.NetworkCredentialName,
                                   requestInfo.NetworkCredentialPassword, requestInfo.HttpExpect100Continue,
                                   requestInfo.ServicePointManagerExpect100Continue, requestInfo.Mycharset, requestInfo.Headers);

            var respone = new ResponeInfo
            {
                HttpCodeState   = httpcode,
                Outcookieheader = outcookieheader,
                ResponeText     = text
            };

            return(respone);
        }