我无法使用 oauth2 登录 Paypal 以获取不记名令牌,在我的 C# 代码中出现 HTTP 500 - Internal Server Error,cUrl 显示 SSL 错误。我是否需要在我的机器上安装任何证书,如果需要 - 我在哪里可以得到它们?
当我直接在浏览器中键入“ https://api.sandbox.paypal.com/v1/oauth2 ”时,会出现绿色挂锁,单击它会显示该站点的 SSL 证书有效。
服务器和单元测试是 C#,但我在使用 cUrl 进行调用时也看到了一个问题:
curl https://api.sandbox.paypal.com/v1/oauth2/token
-H "Accept: application/json"
-H "Accept-Language: en_US"
-u "SOMELONGB64CONTENTHERE/USER:PASSWORD"
-d "grant_type=client_credentials" -v
此调用显示与 SSL 相关的错误:
* About to connect() to api.sandbox.paypal.com port 443 (#0)
* Trying 173.0.82.78... connected
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS alert, Server hello (2):
* SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify faile
d
* Closing connection #0
curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify faile
d
当我将--insecure
选项添加到 cUrl 时,调用会返回预期的内容。
*更新:*当我在我的 Mac 上运行完全相同的 cUrl 命令时,响应正常并且具有我期望的不记名令牌。
C# 中的单元测试代码(截断错误处理和日志记录):
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://api.sandbox.paypal.com/v1/oauth2/token");
request.Method = "POST";
request.Accept = "application/json";
request.Headers.Add("Accept-Language:en_US");
string authInfo = "SOMELONGB64CONTENTHERE/USER:PASSWORD";
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
request.Headers["Authorization"] = "Basic " + authInfo;
using (StreamWriter swt = new StreamWriter(request.GetRequestStream()))
{
swt.Write("grant_type=client_credentials");
}
request.BeginGetResponse((r) =>
{
HttpWebResponse response = request.EndGetResponse(r) as HttpWebResponse; // Exception HTTP500 here
// truncated code that reads the bearer token
}, null);
*更新:*当使用 Fiddler 捕获时,来自该单元测试的原始流量如下:
要求:
POST https://api.sandbox.paypal.com/v1/oauth2/token HTTP/1.1
Accept: application/json
Accept-Language: en_US
Authorization: Basic SOMELONGB64CONTENTHERE/USER:PASSWORD
Host: api.sandbox.paypal.com
Content-Length: 29
Expect: 100-continue
Connection: Keep-Alive
grant_type=client_credentials
回复:
HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
Content-Type: application/json
Content-Length: 118
Date: Sun, 30 Jun 2013 22:21:53 GMT
Connection: close
{"name":"INTERNAL_SERVICE_ERROR","information_link":"https://api.sandbox.paypal.com/docs/api/#INTERNAL_SERVICE_ERROR"}