I saw these post, but they did not work out:
- C# HttpWebRequest The underlying connection was closed: An unexpected error occurred on a send
- The underlying connection was closed: An unexpected error occurred on a send.--- NuGet
You can find the entire code here :https://github.com/te2020/GoEuroAPiClassLibrary/blob/master/GOEuroApi_Requests.cs
Only the relevant part of it(what I think):
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Encoding", "gzip, deflate");
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0");
httpClient.BaseAddress = new Uri("https://www.goeuro.com/");
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "/GoEuroAPI/rest/api/v5/searches");
request.Content = new StringContent(jsonString,
Encoding.UTF8,
"application/json");//CONTENT-TYPE header
My fiddler looks like this and it works.
I get the eror after sending that request:
var response = await httpClient.SendAsync(request);
What did I miss ?