コード例 #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));
            }
        }