Example #1
0
        public WebResponseParameter Get(string Url)
        {
            WebResponseParameter response = HttpUtil.Excute(new WebRequestParameter
            {
                Url    = Url,
                Method = HttpMethod.GET
            });

            return(response);
        }
Example #2
0
        public WebResponseParameter Post(string Url, string json)
        {
            WebResponseParameter response = HttpUtil.Excute(new WebRequestParameter
            {
                Url         = Url,
                Method      = HttpMethod.POST,
                ContentType = HttpContentType.json,
                Json        = json
            });

            return(response);
        }
Example #3
0
        /*
         * IDictionary<string, string> postData = new Dictionary<string, string>();
         *  postData.Add("userName", "登录用户名");
         *  postData.Add("userPwd", "用户名密码");
         */
        public WebResponseParameter Post(string Url, IDictionary <string, string> postData)
        {
            WebResponseParameter response = HttpUtil.Excute(new WebRequestParameter
            {
                Url         = Url,
                Method      = HttpMethod.POST,
                ContentType = HttpContentType.json,
                Parameters  = postData
            });

            return(response);
        }
Example #4
0
        /// <summary>
        /// 返回响应报文
        /// </summary>
        /// <param name="webRequest">HttpWebRequest对象</param>
        /// <param name="requestParameter">请求参数对象</param>
        /// <returns>响应对象</returns>
        static WebResponseParameter SetResponse(HttpWebRequest webRequest, WebRequestParameter requestParameter)
        {
            WebResponseParameter responseParameter = new WebResponseParameter();

            using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
            {
                responseParameter.Uri        = webResponse.ResponseUri;
                responseParameter.StatusCode = webResponse.StatusCode;
                responseParameter.Cookie     = new WebCookieType
                {
                    CookieCollection = webResponse.Cookies,
                    CookieString     = webResponse.Headers["Set-Cookie"]
                };
                using (StreamReader reader = new StreamReader(webResponse.GetResponseStream(), requestParameter.Encoding))
                {
                    responseParameter.Body = reader.ReadToEnd();
                }
            }
            return(responseParameter);
        }