예제 #1
0
        private string HttpsRequstRest(string method, IDictionary<string, string> appParamters, string format)
        {
            StringBuilder urlBuilder = new StringBuilder();
            urlBuilder.Append(restHttpsBase).Append(method).Append("?access_token=").Append(
                HttpUtility.UrlEncode(this.access_token)).Append("&format=");

            if (string.Compare(FORMAT_XML, format, true) == 0)
            {
                urlBuilder.Append(FORMAT_XML);
            }
            else
            {
                urlBuilder.Append(FORMAT_JSON);
            }

            string restResponse = null;

            string queryString = appParamters==null?null:GenerateQueryString(appParamters);//构造应用级参数

            try
            {
                restResponse = new HttpUtils().HttpPost(urlBuilder.ToString(), queryString);

            }
            catch
            {
                throw;
            }

            return restResponse;
        }
예제 #2
0
        private static OAuthMessage AccessTokenRequest(string queryString)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            OAuthMessage access_token = null;
            string jsonresult = null;

            try
            {
                jsonresult = new HttpUtils().HttpPost(tokenUrl, queryString);

            }
            catch (WebException e)
            {
                if (e.Status == WebExceptionStatus.ProtocolError)
                {
                    StreamReader reader = new StreamReader(e.Response.GetResponseStream(), Encoding.UTF8);
                    jsonresult = reader.ReadToEnd();
                }
            }
            if (jsonresult.Contains("error"))
            {
                throw js.Deserialize<OAuthException>(jsonresult);
            }

            jsonresult = jsonresult.Replace(@"\",@"\\");

            access_token = js.Deserialize<OAuthMessage>(jsonresult);

            return access_token;
        }
예제 #3
0
        private string HttpRequstRest(string method, IDictionary<string, string> appParamters, string format)
        {
            if (appParamters == null)
            {
                appParamters = new Dictionary<string, string>();
            }

            appParamters.Add("session_key", this.session_key);
            appParamters.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));

            if (string.Compare(FORMAT_XML, format, true) == 0)
            {
                appParamters.Add("format", FORMAT_XML);
            }
            else
            {
                appParamters.Add("format", FORMAT_JSON);
            }

            string sig = getSignature(appParamters, this.session_secret);
            appParamters.Add("sign", sig);

            string urlParamters = GenerateQueryString(appParamters);

            string result = null;
            try
            {
                result = new HttpUtils().HttpPost(restHttpBase + method, urlParamters);

            }
            catch
            {
                throw;
            }

            return result;
        }