0

I am trying to access the Strava authentication API:

https://developers.strava.com/docs/authentication/

But I keep getting an "An existing connection was forcibly closed by the remote host" error, regardless of how I post my request server side using c#

I have tried both HttpClient and HttpWebRequest

var request = (HttpWebRequest)WebRequest.Create("https://www.strava.com/oauth/token");

var data = Encoding.UTF8.GetBytes("client_id=someid&client_secret=somesecret&refresh_token=sometoken&grant_type=");

request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;

using (var stream = request.GetRequestStream())
{
    stream.Write(data, 0, data.Length);
}

var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

It works perfectly when using JavaScript, jQuery or Postman.

function doPost() {
            $.post("https://www.strava.com/oauth/token",
                {
                    client_id: "someid",
                    client_secret: "somesecret",
                    refresh_token: "sometoken",
                    grant_type: "refresh_token"
                },
                function (data, status) {
                    // done
                });
        }

Any help pointing me in the right direction will be greatly appreciated

Thnx

iAyAy
  • 39
  • 6
  • 1
    Your code is correct, I reproduced the request and I just got back a "400 BadRequest" obviously because I am not sending the correct values. I believe your problem is similar to this one: https://stackoverflow.com/questions/2582036/an-existing-connection-was-forcibly-closed-by-the-remote-host – Bruno Jul 11 '20 at 13:02
  • @Bruno Thank you so much, the question you mentioned is the same issue. I changed the approach a bit and are now actually getting a response :-) – iAyAy Jul 11 '20 at 15:39

0 Answers0