PayPal IPN Bad Request 400 Error

后端 未结 6 2279
挽巷
挽巷 2020-12-05 05:31

Using the PayPal IPN, I keep getting an error 400.

I have been making the script send me emails of $res to see what the response is, inside of the

相关标签:
6条回答
  • 2020-12-05 05:36

    Since you're opening the socket yourself, rather than using an HTTP library such as curl, you need to set the proper HTTP Protocol version and add the HTTP Host header yourself just below the POST line.

    $header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
    $header .= "Host: www.sandbox.paypal.com\r\n";
    
    0 讨论(0)
  • 2020-12-05 05:49

    I was having the same issues and these are the required changes. Some of the answers above dont fix all the problems.

    New format for header:

    $header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Host: www.sandbox.paypal.com\r\n";  // www.paypal.com for a live site
    $header .= "Content-Length: " . strlen($req) . "\r\n";
    $header .= "Connection: close\r\n\r\n";
    

    Note the extra set of \r\n on the last line only. Also, the string compare no longer works because a newline is being inserted in the response from the server so change this:

    if (strcmp ($res, "VERIFIED") == 0) 
    

    to this:

    if (stripos($res, "VERIFIED") !== false)  // do the same for the check for INVALID
    
    0 讨论(0)
  • 2020-12-05 05:49

    Another solution is to trim the $res before comparison..

    $res = fgets ($fp, 1024);
    
    $res = trim($res); //NEW & IMPORTANT
    
    0 讨论(0)
  • 2020-12-05 05:50

    I had the same problem and the best thing is to use the paypal sample code... It works perfectly then : https://www.x.com/developers/PayPal/documentation-tools/code-sample/216623

    0 讨论(0)
  • 2020-12-05 05:57

    https://www.x.com/content/bulletin-ipn-and-pdt-scripts-and-http-1-1

    // post back to PayPal system to validate
    $header .="POST /cgi-bin/webscr HTTP/1.1\r\n";
    $header .="Content-Type: application/x-www-form-urlencoded\r\n";
    $header .="Host: www.paypal.com\r\n";
    $header .="Connection: close\r\n";
    
    0 讨论(0)
  • 2020-12-05 06:02

    I have found PayPals example code using fsockopen not to work properly.

    To make IPN work with PHP I used Aireff's suggestion from Aug 5 and looked at the code using curl technique on x.com site.

    0 讨论(0)
提交回复
热议问题