コード例 #1
0
        /// <summary>
        /// 获取远程字符串.
        ///  Author:   XP-PC/Shaipe
        ///  Created:  09-29-2015
        /// </summary>
        /// <param name="className">类名称.</param>
        /// <param name="actionName">动作名称.</param>
        /// <param name="parameters">参数.</param>
        /// <param name="format">获取数据格式.</param>
        /// <param name="requestMethod">请求方式.</param>
        /// <returns>System.String.</returns>
        public string GetString(string url, string method, string parameters, FormatType format = FormatType.Json, string version = "1.0", string requestMethod = "POST")
        {
            string msg     = string.Empty,
                   content = string.Empty;

            //string url = ServerGroupRoute.GetServerAPIUrl(ApiUrl, GetMethod(className, actionName));

            string reqParameters = AddSign(method, parameters, format, version);

            if (requestMethod.ToUpper() == "POST")
            {
                content = SyncHttp.HttpPost(url, reqParameters, out msg, RequestHeader);
            }
            else
            {
                content = SyncHttp.HttpGet(url, reqParameters, out msg, RequestHeader);
            }

            if (!msg.IsNullOrEmpty())
            {
                new Exceptions("数据接口请求错误:" + msg + "; 请求Url: " + url);
            }

            return(content);
        }
コード例 #2
0
ファイル: SeekRequest.cs プロジェクト: xungong91/GxProgram
        //同步http请求
        public string SyncRequest(string url, string httpMethod, List <Parameter> listParam, List <Parameter> listFile)
        {
            StringBuilder sbqueryString = new StringBuilder();
            string        queryString   = null;

            foreach (Parameter pa in listParam)
            {
                /////////2013年3月18日17:47:04修改为urlEncoding编码
                sbqueryString.AppendFormat("{0}={1}&", pa.Name, UrlEncode(pa.Value));
            }
            if (sbqueryString.Length > 0)
            {
                queryString = sbqueryString.ToString().Substring(0, sbqueryString.Length - 1);
            }

            string   oauthUrl = url;
            SyncHttp http     = new SyncHttp();

            if (httpMethod == "GET")
            {
                return(http.HttpGet(oauthUrl, queryString));
            }
            else if ((listFile == null) || (listFile.Count == 0))
            {
                return(http.HttpPost(oauthUrl, queryString));
            }
            else
            {
                return(http.HttpPostWithFile(oauthUrl, queryString, listFile));
            }
        }
コード例 #3
0
        /// <summary>
        /// 执行API接口请求方法
        /// 传入参数列表,比如接口名称,参数等
        /// </summary>
        /// <param name="method">请求类型</param>
        /// <param name="path">接口名称</param>
        /// <param name="parameters">参数列表</param>
        /// <returns>服务器响应数据</returns>
        public string Request(string method, string path, List <APIParameter> parameters)
        {
            string        responseData = "";
            APIValidation av           = new APIValidation();

            parameters.Add(new APIParameter("access_token", av.GetAccessToken()));
            string url = APIConfig.RennAPIURL + path;

            responseData = new SyncHttp().HttpRequest(method, url, parameters);
            return(responseData);
        }
コード例 #4
0
ファイル: APIValidation.cs プロジェクト: WZDotCMS/WZDotCMS
 public string GetTest(string ApiKey, string SecretKey, string code, string CallBackURL)
 {
     List<APIParameter> paras = new List<APIParameter>() {
                 new APIParameter("grant_type","authorization_code"),
                 new APIParameter("code",code),
                 new APIParameter("client_id", ApiKey),
                 new APIParameter("client_secret", SecretKey),
                 new APIParameter("redirect_uri", CallBackURL)
             };
     string requestUrl = HttpUtil.AddParametersToURL(APIConfig.AccessURL, paras);
     string content = new SyncHttp().HttpPost(requestUrl, "");
     return content;
 }
コード例 #5
0
        /// <summary>
        /// 获取当前应用的最新版本
        /// </summary>
        /// <returns></returns>
        public VersionModel ShowVersion()
        {
            SyncHttp         http  = new SyncHttp();
            List <Parameter> Query = new List <Parameter>();

            Query.Add(new Parameter("app_key", _app_key));
            Query.Add(new Parameter("app_secret", _app_secret));
            string Url      = APIType.GetURL(TypeOption.MD_version);
            string QueryStr = HttpUtility.NormalizeRequestParameters(Query);
            string Result   = http.HttpGet(Url, QueryStr);

            if (!string.IsNullOrEmpty(Result))
            {
                return(XmlSerializationHelper.XmlToObject <VersionModel>(Result));
            }
            return(null);
        }
コード例 #6
0
ファイル: APIValidation.cs プロジェクト: WZDotCMS/WZDotCMS
 /// <summary>
 /// 获取Access Token,
 /// 通过第一步返回的URL获得参数Code的值,就为Authorization Code
 /// </summary>
 /// <returns>返回获得的Access Token</returns>
 public string GetAccessToken(string ApiKey, string SecretKey, string CallBackURL)
 {
     string accessToken = "";
     try
     {
         if (System.Web.HttpContext.Current.Session["renren_token"] == null)
         {
             string authorizationCode = System.Web.HttpContext.Current.Request["code"] ?? "";
             if (authorizationCode != "")
             {
                 List<APIParameter> paras = new List<APIParameter>() {
                 new APIParameter("grant_type","authorization_code"),
                 new APIParameter("code",authorizationCode),
                 new APIParameter("client_id", ApiKey),
                 new APIParameter("client_secret", SecretKey),
                 new APIParameter("redirect_uri", CallBackURL)
             };
                 string requestUrl = HttpUtil.AddParametersToURL(APIConfig.AccessURL, paras);
                 string content = new SyncHttp().HttpPost(requestUrl, "");
                 JavaScriptObject obj = (JavaScriptObject)((JavaScriptArray)JavaScriptConvert.DeserializeObject(content))[0];
                 accessToken = obj["access_token"].ToString();
                 System.Web.HttpContext.Current.Session["renren_token"] = accessToken;
             }
         }
         else
         {
             accessToken = System.Web.HttpContext.Current.Session["renren_token"] as string;
         }
     }
     catch
     {
         accessToken = "";
     }
     // 由于获得Json字符串通过JSON.NET获取之后,还是以字符串形式存在,形如“xxxxx”,包括双引号
     // 所以必须替换掉双引号
     accessToken = accessToken.Replace("\"", "");
     return accessToken;
 }