In my C# application I'm trying to send an HTTP request to an external company outside of our firewall. When I use the below code, I'm getting back an error that the remote site has forcibly closed the connection. I'm assuming I'm doing something incorrectly with the proxy setting but I'm not sure what. Our proxy does not require authentication.
var content = new StringContent(JsonConvert.SerializeObject(obj), Encoding.UTF8, "application/json");
using (var handler = new HttpClientHandler()) {
handler.Proxy = new WebProxy("http://proxy.my.domain.com:911");
using (var client = new HttpClient(handler: handler, disposeHandler: false)) {
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "...");
var response = await client.PostAsync($"https://...", content);
I've printed out the encoded JSON that gets sent and if I just do things manually via curl
the request goes right though, so I'm sure that my URL, bearer token and JSON are all correct.