Я пытаюсь сделать http-пост на удаленный URL-адрес с контроллера ASP.NET MVC. Приложение ASP.NET MVC работает в Visual Studio 2017 на iisexpress с использованием https://localhost:44302/. Я получаю The underlying connection was closed: An unexpected error occurred on a send.
и Authentication failed because the remote party has closed the transport stream.
ошибки. Я вызвал ту же службу URL с теми же параметрами, используя curl из git bash, и это работает. По какой-то причине это не работает из Visual Studio. Это как-то связано с localhost и ssl-сертификатом разработки?
Это ошибка:
System.Net.WebException
HResult = 0x80131509
Сообщение = базовое соединение было закрыто: при отправке произошла непредвиденная ошибка.
Источник = Plugin.Payment.Stripe
Внутреннее исключение 1:
IOException: аутентификация не удалась, потому что удаленная сторона закрыла транспортный поток.
Это код, который я использую в своем контроллере:
WebRequest wrequest = WebRequest.Create("https://connect.stripe.com/oauth/token");
wrequest.UseDefaultCredentials = true;
// Set the Method property of the request to POST.
wrequest.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "client_secret=" + CacheHelper.GetSettingDictionary("StripeApiKey").Value;
postData += "&code=" + code;
postData += "grant_type=authorization_code";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
wrequest.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
wrequest.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = wrequest.GetRequestStream();
Тот же вызов прекрасно работает с curl из bash:
curl -X POST https://connect.stripe.com/oauth/token \
-d client_secret=SECRET_KEY \
-d code=CODE_KEY \
-d grant_type=authorization_code
Я попробовал ответ в этой ссылке , но это не сработало, поэтому я думаю, что это может быть связано с сертификатом ssl