async public Task <dynamic> GetAsync(string path) { try { var url = intento.serverUrl + path; LogHttpRequest("GET", intento.serverUrl + path, null, client.DefaultRequestHeaders.ToString()); HttpResponseMessage response = await client.GetAsync(url); LogHttpAfterSend(); dynamic jsonResult = await GetJson(response); LogHttpResponse(jsonResult); if (response.StatusCode != HttpStatusCode.OK) { Exception ex = (Exception)IntentoException.Make(response, jsonResult); LogHttpException(ex); throw ex; } return(jsonResult); } catch (Exception ex) { LogHttpException(ex); throw; } }
async public Task <dynamic> GetAsync(string path, Dictionary <string, string> additionalParams = null) { try { var url = MakeUrl(path, additionalParams); LogHttpRequest("GET", url, null, client.DefaultRequestHeaders.ToString()); using (HttpResponseMessage response = await client.GetAsync(url)) { LogHttpAfterSend(); dynamic jsonResult = await GetJson(response); LogHttpResponse(jsonResult); if (response.StatusCode != HttpStatusCode.OK) { Exception ex = (Exception)IntentoException.Make(response, jsonResult); LogHttpException(ex); throw ex; } return(jsonResult); } } catch (Exception ex) { LogHttpException(ex); throw; } }
async public Task <dynamic> PostAsync(string path, dynamic json) { try { string jsonData = JsonConvert.SerializeObject(json); HttpContent requestBody = new StringContent(jsonData); LogHttpRequest("POST", intento.serverUrl + path, jsonData, client.DefaultRequestHeaders.ToString()); HttpResponseMessage response = await client.PostAsync(intento.serverUrl + path, requestBody); LogHttpAfterSend(); dynamic jsonResult = await GetJson(response); LogHttpResponse(jsonResult); if (response.StatusCode != HttpStatusCode.OK) { Exception ex = (Exception)IntentoException.Make(response, jsonResult); LogHttpException(ex); throw ex; } return(jsonResult); } catch (Exception ex) { LogHttpException(ex); throw; } }
async public Task <dynamic> PostAsync(string path, dynamic json, Dictionary <string, string> special_headers = null, Dictionary <string, string> additionalParams = null, bool useSyncwrapper = false) { try { string jsonData = JsonConvert.SerializeObject(json); using (HttpContent httpContent = new StringContent(jsonData)) { var url = MakeUrl(path, additionalParams, useSyncwrapper); if (special_headers != null && special_headers.Count != 0) { foreach (KeyValuePair <string, string> pair in special_headers) { httpContent.Headers.Add(pair.Key, pair.Value); } } LogHttpRequest("POST", url, jsonData, client.DefaultRequestHeaders.ToString()); using (HttpResponseMessage response = await client.PostAsync(url, httpContent)) { LogHttpAfterSend(); dynamic jsonResult = await GetJson(response); LogHttpResponse(jsonResult); if (response.StatusCode != HttpStatusCode.OK) { Exception ex = (Exception)IntentoException.Make(response, jsonResult); LogHttpException(ex); throw ex; } return(jsonResult); } } } catch (Exception ex) { LogHttpException(ex); throw; } }