コード例 #1
0
        private static string GetJson(string url, Params parameters, ApiConfig env, Dictionary <string, string> headers, out HttpStatusCode code)
        {
            url = String.Format("{0}?{1}", url, parameters.GetQuery());
            HttpWebRequest request = GetRequest(url, HttpMethod.GET, headers, env);

            return(SendRequest(request, out code));
        }
コード例 #2
0
        private static Task <(string content, HttpStatusCode code)> GetJson(string url, Params parameters, ApiConfig env, Dictionary <string, string> headers, bool IsList)
        {
            url = String.Format("{0}?{1}", url, parameters.GetQuery(IsList));
            HttpWebRequest request = GetRequest(url, HttpMethod.GET, headers, env);

            return(SendRequest(request));
        }
コード例 #3
0
        private static string GetJson(string relativeUrl, Params parameters, ApiConfig env, Dictionary <string, string> headers, out HttpStatusCode code, bool IsList)
        {
            var query = parameters.GetQuery(IsList);

            HttpWebRequest request = GetRequest(relativeUrl, HttpMethod.GET, headers, env, query);

            return(SendRequest(request, out code));
        }
コード例 #4
0
        public static ListResult GetList(string url, Params parameters, Dictionary <string, string> headers, ApiConfig env)
        {
            url = String.Format("{0}?{1}", url, parameters.GetQuery(true));
            HttpRequestMessage request = GetRequestMessage(url, HttpMethod.GET, parameters, headers, env);
            var response = httpClient.SendAsync(request).ConfigureAwait(false).GetAwaiter().GetResult();
            var json     = response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult();

            if (response.IsSuccessStatusCode)
            {
                ListResult result = new ListResult(response.StatusCode, json);
                return(result);
            }
            else
            {
                HandleException(response);
                return(null);
            }
        }
コード例 #5
0
        public static async Task <EntityResult> Post(string url, Params parameters, Dictionary <string, string> headers, ApiConfig env)
        {
            HttpWebRequest request = GetRequest(url, HttpMethod.POST, headers, env);

            byte[] paramsBytes =
                Encoding.GetEncoding(env.Charset).GetBytes(parameters.GetQuery(false));

            //request.ContentLength = paramsBytes.Length;
            request.ContentType =
                String.Format("application/x-www-form-urlencoded;charset={0}", env.Charset);
            using (Stream stream = request.GetRequestStreamAsync().Result)
            {
                stream.Write(paramsBytes, 0, paramsBytes.Length);

                (string json, HttpStatusCode code) = await SendRequest(request);

                EntityResult result = new EntityResult(code, json);
                return(result);
            }
        }
コード例 #6
0
        private static HttpRequestMessage BuildRequest(string url, HttpMethod method, Params parameters, ApiConfig env)
        {
            HttpRequestMessage request;

            System.Net.Http.HttpMethod meth = new System.Net.Http.HttpMethod(method.ToString());
            if (method.Equals(HttpMethod.POST))
            {
                byte[] paramBytes = Encoding.GetEncoding(env.Charset).GetBytes(parameters.GetQuery(false));
                string postData   = Encoding.GetEncoding(env.Charset).GetString(paramBytes, 0, paramBytes.Length);
                request = new HttpRequestMessage(meth, new Uri(url))
                {
                    Content = new StringContent(postData, Encoding.UTF8, "application/x-www-form-urlencoded")
                };
            }
            else
            {
                request = new HttpRequestMessage(meth, new Uri(url));
            }
            return(request);
        }
コード例 #7
0
 public static Task <EntityResult> GetAsync(string url, Params parameters, Dictionary <string, string> headers, ApiConfig env)
 {
     url = String.Format("{0}?{1}", url, parameters.GetQuery(false));
     return(GetEntityResultAsync(url, parameters, headers, env, HttpMethod.GET));
 }
コード例 #8
0
 public static ListResult GetList(string url, Params parameters, Dictionary <string, string> headers, ApiConfig env)
 {
     url = String.Format("{0}?{1}", url, parameters.GetQuery(true));
     return(GetListAsync(url, parameters, headers, env).GetAwaiter().GetResult());
 }
コード例 #9
0
        public static EntityResult Post(string url, Params parameters, Dictionary<string, string> headers, ApiConfig env)
        {
            HttpWebRequest request = GetRequest(url, HttpMethod.POST, headers, env);
            byte[] paramsBytes =
                Encoding.GetEncoding(env.Charset).GetBytes(parameters.GetQuery());

            request.ContentLength = paramsBytes.Length;
            request.ContentType =
                String.Format("application/x-www-form-urlencoded;charset={0}",env.Charset);
            using (Stream stream = request.GetRequestStream())
            {
                stream.Write(paramsBytes, 0, paramsBytes.Length);

                HttpStatusCode code;
                string json = SendRequest(request, out code);

                EntityResult result = new EntityResult(code, json);
                return result;
            }
        }
コード例 #10
0
 private static string GetJson(string url, Params parameters, ApiConfig env, Dictionary<string, string> headers, out HttpStatusCode code)
 {
     url = String.Format("{0}?{1}", url, parameters.GetQuery());
     HttpWebRequest request = GetRequest(url, HttpMethod.GET, headers, env);
     return SendRequest(request, out code);
 }