public static EntityResult Get(string url, Params parameters, Dictionary<string, string> headers, ApiConfig env) { HttpStatusCode code; string json = GetJson(url, parameters, env, headers, out code); EntityResult result = new EntityResult(code, json); return result; }
private static EntityResult GetEntityResult(String url, Params parameters, Dictionary <string, string> headers, ApiConfig env, HttpMethod meth) { HttpRequestMessage request = GetRequestMessage(url, meth, parameters, headers, env); var response = httpClient.SendAsync(request).ConfigureAwait(false).GetAwaiter().GetResult(); var json = response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); if (response.IsSuccessStatusCode) { EntityResult result = new EntityResult(response.StatusCode, json); return(result); } else { HandleException(response); return(null); } }
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); } }
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; } }