在 UPS OAuth API 集成中,我们遇到 API 响应超时的问题。当我们尝试使用 CURL 发出请求时,我们会收到 http 302 成功响应。但在 RestSharp / C# 中,我们遇到超时。
C#代码:
var restClient = new RestClient("https://onlinetools.ups.com/security/v1/oauth/authorize");
var request = new RestRequest(Method.GET);
request.AddQueryParameter("client_id", "MyclientId");
request.AddQueryParameter("redirect_uri", "https://local.myclient.com/Seller/Carrier/UpsOAuthCallback");
request.AddQueryParameter("response_type", "code");
request.AddQueryParameter("scope", "read");
request.AddQueryParameter("state", "superstate");
request.AddQueryParameter("code_challenge", "boxes2021");
var response = await restClient.ExecuteAsync(request);
CURL 命令:
curl -v -i -X GET 'https://onlinetools.ups.com/security/v1/oauth/authorize?client_id=MyclientId&redirect_uri=https://local.myclient.com/Seller/Carrier/UpsOAuthCallback&response_type=code&state=superstate&scope=read&code_challenge=boxes@2021'
我尝试了 OAuth 的代码块,但超时。但是当我在终端中使用 CURL 尝试请求时,我得到了成功的响应。
你应该使用redirect=false
var client = new RestClient("https://onlinetools.ups.com")
{
FollowRedirects = false
};
var request = new RestRequest("/security/v1/oauth/authorize", Method.Get);
request.AddParameter("client_id", "my_client_id");
request.AddParameter("redirect_uri", "https://localhost.blabla.com/Seller/Carrier/UpsOAuthCallback");
request.AddParameter("response_type", "code");
request.AddParameter("state", "superstate");
request.AddParameter("scope", "read");
request.AddParameter("code_challenge", "boxes2021");
var response = await client.ExecuteAsync(request);
Console.WriteLine("Status Code: " + response.StatusCode);
Console.WriteLine("Response Content: " + response.Content);