private T DoSend <T>(RSharp.Method method, object body) { _request.AddParameter( "application/json", Newtonsoft.Json.JsonConvert.SerializeObject(body), ParameterType.RequestBody); _request.Timeout = 100000; // ms var response = _restClient.Execute(_request, method); if (response.IsSuccessful) { return(Deserialize <T>(response)); } if (response.StatusCode == 0 && response.ErrorMessage.Contains("Section=ResponseStatusLine")) { return(Deserialize <T>(response)); } if (response.ErrorException != null) { throw RestClientFactory.CreateErrorException(_restClient, response); } throw RestClientFactory.CreateFailedException(_restClient, response); }
private T DoSend <T>(HttpMethod method, object body) { _request.Method = method; try { _request.Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json"); var req = _request.ToRestClientRequest(_restClient.BaseAddress); //Logging.WriteToFileThreadSafe(DateTime.Now.ToString("o") + " " + req.ToString(), FILE_LOG); var response = _restClient.SendAsync(_request).Result; var resp = response.ToRestClientRequest(); //Logging.WriteToFileThreadSafe(DateTime.Now.ToString("o") + " " + resp.ToString(), FILE_LOG); if (response.IsSuccessStatusCode) { return(Deserialize <T>(response)); } var errorMessage = response.Content.ReadAsStringAsync().Result; if (response.StatusCode == 0 && errorMessage.Contains("Section=ResponseStatusLine")) { return(Deserialize <T>(response)); } throw RestClientFactory.CreateFailedException(_restClient, req, resp, response); } catch (HttpRequestException ex) { //Logging.WriteToFileThreadSafe(DateTime.Now.ToString("o") + " ERROR: " + _request.ToRestClientRequest(_restClient.BaseAddress).ToString(), FILE_LOG); //Logging.WriteToFileThreadSafe(DateTime.Now.ToString("o") + " EXCEP: " + ex.Message, FILE_LOG); throw RestClientFactory.CreateFailedException(_restClient, _request, ex); } }
private T DoSend <T>(HttpMethod method) { try { _request.Method = method; var req = _request.ToRestClientRequest(_restClient.BaseAddress); //Logging.WriteToFileThreadSafe(DateTime.Now.ToString("o") + " " + req.ToString(), FILE_LOG); HttpResponseMessage response = _restClient.SendAsync(_request).Result; var resp = response.ToRestClientRequest(); //Logging.WriteToFileThreadSafe(DateTime.Now.ToString("o") + " " + resp.ToString(), FILE_LOG); if (response.IsSuccessStatusCode) { return(Deserialize <T>(response)); } //var errorMessage = response.Content.ReadAsStringAsync().Result; //if (response.StatusCode == 0 && errorMessage.Contains("Section=ResponseStatusLine")) //{ // return Deserialize<T>(response); //} throw RestClientFactory.CreateFailedException(_restClient, req, resp, response); } catch (HttpRequestException ex) { //Logging.WriteToFileThreadSafe(DateTime.Now.ToString("o") + " ERROR: " + _request.ToRestClientRequest(_restClient.BaseAddress).ToString(), FILE_LOG); //Logging.WriteToFileThreadSafe(DateTime.Now.ToString("o") + " EXCEP: " + ex.Message, FILE_LOG); throw RestClientFactory.CreateFailedException(_restClient, _request, ex); } }
private T DoSend <T>(RSharp.Method method) { var response = _restClient.Execute(_request, method); if (response.IsSuccessful) { return(Deserialize <T>(response)); } if (response.ErrorException != null) { throw RestClientFactory.CreateErrorException(_restClient, response); } throw RestClientFactory.CreateFailedException(_restClient, response); }
private void DoSend(RSharp.Method method, object body) { _request.AddParameter( "application/json", Newtonsoft.Json.JsonConvert.SerializeObject(body), ParameterType.RequestBody); var response = _restClient.Execute(_request, method); if (response.ErrorException != null) { throw RestClientFactory.CreateErrorException(_restClient, response); } if (!response.IsSuccessful) { throw RestClientFactory.CreateFailedException(_restClient, response); } }
private T DoSend <T>(RSharp.Method method) { _request.Timeout = 100000; // ms var response = _restClient.Execute(_request, method); if (response.IsSuccessful) { return(Deserialize <T>(response)); } if (response.StatusCode == 0 && response.ErrorMessage.Contains("Section=ResponseStatusLine")) { return(Deserialize <T>(response)); } if (response.ErrorException != null) { throw RestClientFactory.CreateErrorException(_restClient, response); } throw RestClientFactory.CreateFailedException(_restClient, response); }
private void DoSend(RSharp.Method method, object body) { _request.AddParameter( "application/json", Newtonsoft.Json.JsonConvert.SerializeObject(body), ParameterType.RequestBody); _request.Timeout = 100000; // ms //Console.WriteLine("body: " + Newtonsoft.Json.JsonConvert.SerializeObject(body)); var response = _restClient.Execute(_request, method); //Console.WriteLine("Error messag: e" + response.ErrorMessage); //Console.WriteLine("ResponseStatus: " + response.ResponseStatus.ToString()); //Console.WriteLine("StatusDescription: " + response.StatusDescription); //Console.WriteLine("StatusCode: " + response.StatusCode); if (response.StatusCode == 0 && response.ErrorMessage.Contains("Section=ResponseStatusLine")) { return; } if (response.ErrorException != null) { throw RestClientFactory.CreateErrorException(_restClient, response); } if (!response.IsSuccessful) { throw RestClientFactory.CreateFailedException(_restClient, response); } }