0

我正在尝试访问 Strava 身份验证 API:

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

但我不断收到“现有连接被远程主机强行关闭”错误,无论我如何使用 c# 发布我的请求服务器端

我已经尝试过 HttpClient 和 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();

它在使用 JavaScript、jQuery 或 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
                });
        }

任何为我指明正确方向的帮助将不胜感激

谢谢

4

0 回答 0