测试快速结账集成时请求超时

时间:2014-11-25 23:49:07

标签: java paypal paypal-sandbox

这是我第一次使用PayPal API,我正在尝试使用沙盒帐户测试带有沙盒帐户的java Web应用程序中的快速结帐集成,我在第一步遇到问题。我正在调用SetExpressCheckout操作,我收到此错误:“TIMESTAMP = 2014%2d11%2d25T15%3a19%3a14Z& CORRELATIONID = 523b6bcbe502f& ACK =失败& L_ERRORCODE0 = 10001& L_SHORTMESSAGE0 =内部%20错误& L_LONGMESSAGE0 =超时%20processing%20request

正如您在L_LONGMESSAGE0中看到的那样,描述是“超时处理请求”,我不知道它是否相关,但TIMESTAMP提前3小时(我在GMT-3中,所以当我发送请求时这是12:19:14而不是15:19:14)。除此之外,我正在根据PayPal的帮助构建我的URL,这是一个示例(使用为沙盒帐户提供的默认测试用户,密码和签名):

https://api-3t.sandbox.paypal.com/nvp?USER=sdk-three_api1.sdk.com&PWD=QFZCWN5HZM8VBG7Q&SIGNATURE=A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU&METHOD=SetExpressCheckout&VERSION=99.0&RETURNURL=http%3A%2F%2Flocalhost%3A8080%2Fmysite%2Fsomepage&CANCELURL=http%3A%2F%2Flocalhost%3A8080%mysite%2Ferror&PAYMENTREQUEST_0_PAYMENTACTION=Sale&PAYMENTREQUEST_0_AMT=10.00

这是完整的代码:

String sUrl = "https://api-3t.sandbox.paypal.com/nvp?USER=sdk-three_api1.sdk.com&...."; //the full URL shown above
URL obj = new URL(sUrl);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer sbResponse = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    sbResponse.append(inputLine);
}
in.close();

每次我读取响应时,都会看到“超时处理请求”消息(我也尝试过不对请求参数进行编码,结果相同)。有谁知道这里发生了什么,或者至少是一个提示,所以我可以检查一下?我发现与此错误相关的大多数帖子都是针对php的,并且是由参数问题引起的(编码错误,缺少参数等)。
在此先感谢,问候。

1 个答案:

答案 0 :(得分:0)

好吧,似乎paypal不喜欢我编写它的方式,因此我更改了HttpURLConnection org.apache.http.client.methods.HttpPost,所以这是我的代码(工作):

    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(SANBOX_URL);
    post.setHeader("User-Agent", "Mozilla/5.0"); 
    List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
    urlParameters.add(new BasicNameValuePair(USER, "SANDBOX_USER"));
    urlParameters.add(new BasicNameValuePair(PASSWORD, "SANDBOX_PWD"));
    urlParameters.add(new BasicNameValuePair(SIGNATURE, "SANDBOX_SIGNATURE"));
    urlParameters.add(new BasicNameValuePair(VERSION, "VERSION"));
    urlParameters.add(new BasicNameValuePair(ACTION, "ACTION"));
    urlParameters.add(new BasicNameValuePair(AMOUNT, "AMOUNT"));
    urlParameters.add(new BasicNameValuePair(RETURN_URL, "RETURN_URL"));
    urlParameters.add(new BasicNameValuePair(CANCEL_URL, "CANCEL_URL"));
    urlParameters.add(new BasicNameValuePair(METHOD, "METHOD"));

    post.setEntity(new UrlEncodedFormEntity(urlParameters));

    HttpResponse response = client.execute(post);


我必须改变的另一件事是不编码参数的值;一旦我做了所有这些改变,最后我得到了#34; TOKEN = XXXX&amp; TIMESTAMP = 2014%2d11%2d27T00%3a08%3a29Z&amp; CORRELATIONID = XXXX&amp; ACK =成功&amp; VERSION = 119%2e0&amp; BUILD = XXXX&#34 ;.
希望能帮助别人