Beispiel #1
0
        public string Request(string url, HttpRequestParameter parameter, HttpMethod method, HttpHeader headers)
        {
            string _params = string.Empty;

            if (parameter != null && parameter.Count > 0)
            {
                _params = parameter.ToString();
            }

            if (method == HttpMethod.GET)
            {
                if (url.Contains("?"))
                {
                    url = url + "&" + _params;
                }
                else
                {
                    url = url + "?" + _params;
                }

                return HttpGet(url, headers);
            }
            else
            {
                return HttpPost(url, _params, headers);
            }
        }
Beispiel #2
0
        public HttpResponse HttpPostJson(string uri, HttpRequestParameter getHttpParameters, string json)
        {
            if (getHttpParameters != null && getHttpParameters.Count > 0)
            {
                uri = getHttpParameters.ToString(uri);
            }

            return HttpPost(uri, json, "application/json");
        }
Beispiel #3
0
        public HttpResponse HttpGet(string uri, HttpRequestParameter httpParameters)
        {
            if (httpParameters != null && httpParameters.Count > 0)
            {
                uri = httpParameters.ToString(uri);
            }

            return HttpRequest(uri, null, "GET", "application/json");
        }
Beispiel #4
0
        public HttpResponse HttpPost(string uri, HttpRequestParameter getHttpParameters, HttpRequestParameter postHttpParameters)
        {
            if (getHttpParameters != null && getHttpParameters.Count > 0)
            {
                uri = getHttpParameters.ToString(uri);
            }

            return HttpPost(uri, postHttpParameters.ToString(), "application/x-www-form-urlencoded");
        }
Beispiel #5
0
        private HttpResponse HttpPutXml(string uri, HttpRequestParameter getHttpParameters, string xml)
        {
            if (getHttpParameters != null && getHttpParameters.Count > 0)
            {
                uri = getHttpParameters.ToString(uri);
            }

            return HttpPut(uri, xml, "application/xml");
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            IHttpProvider httpProvider = new HttpProvider();

            // 1. 模拟一个Get请求方式
            //HttpResponseParameter responseParameter1 = httpProvider.Excute(new HttpRequestParameter
            //{
            //    Url = "http://www.baidu.com",
            //    IsPost = false,
            //    Encoding = Encoding.UTF8
            //    //Cookie = new HttpCookieType() 如果需要Cookie
            //});
            //System.Console.WriteLine(responseParameter1.Body);

            // 2. 模拟一个Post请求方式(例:登录)
            //IDictionary<string, string> postData = new Dictionary<string, string>();
            //postData.Add("userName", "登录用户名");
            //postData.Add("userPwd", "用户名密码");
            //HttpResponseParameter responseParameter2 = httpProvider.Excute(new HttpRequestParameter
            //{
            //    Url = "你的登录url",
            //    IsPost = true,
            //    Encoding = Encoding.UTF8,
            //    Parameters = postData
            //});
            //System.Console.WriteLine(responseParameter2.Body);

            // 1. 模拟一个Get请求方式
            //http://lbfjapi.wsdict.com:8000/xpapi.ashx?method=xpshop.trades.sold.get&page_no=1&page_size=100

            //3.模拟一个Get请求方式  带参数
            IDictionary <string, string> postData = new Dictionary <string, string>();

            postData.Add("userName", "登录用户名");
            postData.Add("userPwd", "用户名密码");

            HttpRequestParameter HttpReq = new HttpRequestParameter
            {
                //Url = "http://www.baidu.com",
                Url        = "http://lbfjapi.wsdict.com:8000/xpapi.ashx?method=xpshop.shipping.type.get",
                IsPost     = false,
                Encoding   = Encoding.UTF8,
                Parameters = postData
                             //Cookie = new HttpCookieType() 如果需要Cookie
            };

            System.Console.WriteLine("请求数据为:" + HttpReq.ToString());
            HttpResponseParameter responseParameter3 = httpProvider.Excute(HttpReq);

            System.Console.WriteLine(responseParameter3.Body);

            System.Console.ReadLine();
        }
Beispiel #7
0
        /// <summary>
        /// The Message API is used to post messages to the user’s contacts. After using the Contact API, you can send messages to the retrieved contacts.
        /// </summary>
        /// <param name="token">A valid session token,which is fetch from Access Token API.</param>
        /// <returns></returns>
        public string ExecuteAPI(Guid token)
        {
            string url = string.Format(Constants.APIRootDomain + Endpoint, token);

            HttpRequestParameter httprequestparameter = new HttpRequestParameter();

            httprequestparameter.Add("to", _To);
            httprequestparameter.Add("subject", _Subject);
            httprequestparameter.Add("message", _Message);

            return(client.Request(url + "&" + httprequestparameter.ToString(), null, HttpMethod.POST));
        }
Beispiel #8
0
        /// <summary>
        /// The Status API is used to update the status on the user’s wall.
        /// </summary>
        /// <param name="token">A valid session token,which is fetch from Access Token API.</param>
        /// <returns></returns>
        public string ExecuteAPI(Guid token)
        {
            string url = string.Format(Constants.APIRootDomain + Endpoint, token);

            HttpRequestParameter httprequestparameter = new HttpRequestParameter();

            httprequestparameter.Add("title", _title);
            httprequestparameter.Add("url", _url);
            httprequestparameter.Add("imageurl", _imageurl);
            httprequestparameter.Add("status", _status);
            httprequestparameter.Add("caption", _caption);
            httprequestparameter.Add("description", _description);

            return(client.Request(url + "&" + httprequestparameter.ToString(), null, HttpMethod.POST));
        }
        /// <summary>
        /// The Status API is used to update the status on the user’s wall.
        /// </summary>
        /// <param name="token">A valid session token,which is fetch from Access Token API.</param>
        /// <returns></returns>
        public string ExecuteAPI(Guid token)
        {
            string url = string.Format(Constants.APIRootDomain + Endpoint, token);

            HttpRequestParameter httprequestparameter = new HttpRequestParameter();
            httprequestparameter.Add("title", _title);
            httprequestparameter.Add("url", _url);
            httprequestparameter.Add("imageurl", _imageurl);
            httprequestparameter.Add("status", _status);
            httprequestparameter.Add("caption", _caption);
            httprequestparameter.Add("description", _description);

            return client.Request(url + "&" +httprequestparameter.ToString()  , null, HttpMethod.POST);
        }
Beispiel #10
0
        /// <summary>
        /// The Message API is used to post messages to the user’s contacts. After using the Contact API, you can send messages to the retrieved contacts.
        /// </summary>
        /// <param name="token">A valid session token,which is fetch from Access Token API.</param>
        /// <returns></returns>
        public string ExecuteAPI(Guid token)
        {
            string url = string.Format(Constants.APIRootDomain + Endpoint, token);

            HttpRequestParameter httprequestparameter = new HttpRequestParameter();
            httprequestparameter.Add("to", _To);
            httprequestparameter.Add("subject", _Subject);
            httprequestparameter.Add("message", _Message);

            return client.Request(url + "&" + httprequestparameter.ToString(), null, HttpMethod.POST);
        }