简体   繁体   English

Paypal API登录停止工作

[英]Paypal API login stopped working

I can't login into Paypal using oauth2 to get a bearer token, getting HTTP 500 - Internal Server Error in my C# code, cUrl shows SSL error. 我无法使用oauth2登录到Paypal以获取承载令牌,而在C#代码中却出现HTTP 500-Internal Server Error,cUrl显示SSL错误。 Do I need to install any certificates on my machine and if so - where do I get them? 我是否需要在计算机上安装任何证书,如果需要-从哪里获得证书?

When I type " https://api.sandbox.paypal.com/v1/oauth2 " directly in my browser the green padlock shows up, clicking on it shows the site's SSL certificate is valid. 当我直接在浏览器中键入“ https://api.sandbox.paypal.com/v1/oauth2 ”时,会出现绿色的挂锁,单击它会显示该站点的SSL证书有效。

The server and unit tests are C#, but I see an issue when making the calls with cUrl too: 服务器测试和单元测试都是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

this call shows an error related to SSL: 该调用显示与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

When I add the --insecure option to cUrl the call returns what's expected. 当我将--insecure选项添加到cUrl时,该调用将返回预期的结果。

* UPDATE: * when I run the exact same cUrl command on my Mac the response is OK and has the bearer token I expect. * 更新:*当我在Mac上运行完全相同的cUrl命令时,响应正常,并具有我期望的承载令牌。

The unit test code in C# (truncated error handling and logging): 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);

* UPDATE: * When captured with Fiddler the raw traffic from that unit test is as follows: * 更新:*用Fiddler捕获时,来自该单元测试的原始流量如下:

Request: 请求:

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

Response: 响应:

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"}

The certificate seems to be OK and valid and issued by VeriSign, expiring in 2016. Is it possible that cUrl simply can't handle it correctly? 该证书似乎是有效的,并由VeriSign颁发,于2016年到期。cUrl是否有可能根本无法正确处理它?

I think your code is wrong, see here: http://msdn.microsoft.com/en-us/library/d4cek6cc.aspx 我认为您的代码有误,请参阅此处: http : //msdn.microsoft.com/zh-cn/library/d4cek6cc.aspx

Your application cannot mix synchronous and asynchronous methods for a particular request. 您的应用程序不能为特定请求混合同步和异步方法。 If you call the GetRequestStream method, you must use the GetResponse method to retrieve the response. 如果调用GetRequestStream方法,则必须使用GetResponse方法来检索响应。

Apparently this was due to a breaking change in Paypal's API. 显然,这是由于Paypal API发生了重大变化。 Another SO post lead to Paypal's own C# wrappers git , where around line 80 you can see the ContentType header set to one of two values: 另一个SO帖子指向Paypal自己的C#包装程序git ,其中在第80行附近,您可以看到ContentType标头设置为两个值之一:

httpRequest.ContentType = "application/x-www-form-urlencoded"; httpRequest.ContentType =“ application / x-www-form-urlencoded”;

OR 要么

httpRequest.ContentType = "application/json"; httpRequest.ContentType =“ application / json”;

The breaking change was introduced recently, the fix is from 06/20/13. 最近引入了重大更改,修复程序从13年6月20日开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM