0

I have a problem when I trying to make post request by HttpClient. I get InnerException"The underlying connection was closed: An unexpected error occurred on a send.".

string encodedCredentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(login + ":" + password));

HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", encodedCredentials);

var content = new StringContent(body);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

return await client.PostAsync(new Uri("https://url"), content);

If I make the same request by Postman everything works fine. Are any idea what problem can be?

Y. Ivan
  • 109
  • 1
  • 9
  • Use a sniffer like wireshark or fiddler to compare request using Postman and your code. – jdweng Jan 05 '17 at 12:27
  • Is there other way to fix that without using ServicePointManager.SecurityProtocol? – Y. Ivan Jan 05 '17 at 14:03
  • Not sure I understand the question. Did you use a sniffer or find issues when using Sniffer? Usually issues like this require adding missing Headers to the HTML Request. It doesn't always mean a SSL Certificate is required. If you are working with Postman, then it doesn't mean that anything additional needs to be added to your PC configuration. So the answer that this is a duplicate is wrong. An existing certificate may need to be added to the HTML header. But without using a sniffer it is hard to determine. – jdweng Jan 05 '17 at 17:55

0 Answers0