public HttpResponse Post(string path, string body) { var url = _options.GetApiUrl() + "/" + path; try { var data = new StringContent(body, Encoding.UTF8, JsonMediaType); var response = _client.PostAsync(url, data).Result; if (response != null) { try { var b = response.Content.ReadAsStringAsync().Result; return(new HttpResponse(true, (int)response.StatusCode, b)); } catch (Exception e) { Logger.Warn("Failed to parse response body: " + e); return(new HttpResponse(false, (int)response.StatusCode, null)); } } } catch (Exception e) { Logger.Warn("Could not post request: " + e); } return(new HttpResponse(false, 500, null)); }
public void ParseConfigFileCorrectlyTest() { SecureNativeOptions options = ConfigurationManager.LoadConfig(); Assert.IsNotNull(options); Assert.AreEqual("SOME_API_KEY", options.GetApiKey()); Assert.AreEqual("SOME_API_URL", options.GetApiUrl()); Assert.AreEqual(true, options.IsAutoSend()); Assert.AreEqual(false, options.IsDisabled()); Assert.AreEqual(FailOverStrategy.FAIL_CLOSED, options.GetFailOverStrategy()); Assert.AreEqual(1000, options.GetInterval()); Assert.AreEqual("fatal", options.GetLogLevel()); Assert.AreEqual(100, options.GetMaxEvents()); Assert.AreEqual(1500, options.GetTimeout()); Assert.AreEqual(1, options.GetProxyHeaders().Length); }