Asked  7 Months ago    Answers:  5   Viewed   38 times

I am using PHP with the Amazon Payments web service. I'm having problems with some of my requests. Amazon is returning an error as it should, however the way it goes about it is giving me problems.

Amazon returns XML data with a message about the error, but it also throws an HTTP 400 (or even 404 sometimes). This makes file_get_contents() throw an error right away and I have no way to get the content. I've tried using cURL also, but never got it to give me back a response.

I really need a way to get the XML returned regardless of HTTP status code. It has an important "message" element that gives me clues as to why my billing requests are failing.

Does anyone have a cURL example or otherwise that will allow me to do this? All my requests currently use file_get_contents() but I am not opposed to changing them. Everyone else seems to think cURL is the "right" way.

 Answers

90

You have to define custom stream context (3rd argument of function file_get_contents) with ignore_errors option on.

Wednesday, March 31, 2021
 
LaKaede
answered 7 Months ago
11

probably an answer here: (if protocol is the issue)

How to get file_get_contents() to work with HTTPS?

Saturday, May 29, 2021
 
godot
answered 5 Months ago
73

505 means HTTP version not supported, so I'm assuming CURL is trying to make the request using an HTTP version that is not supported by the other service. On your code try to see if you can tweak the HTTP version to 1.0 and see if it works.

Saturday, May 29, 2021
 
braindamage
answered 5 Months ago
44

You can try CURL library. You can send multiple request parallel at same time with CURL_MULTI_EXEC

Example:

$ch = curl_init('http_url'); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
$c = curl_exec($ch); 
$info = curl_getinfo($ch, CURLINFO_HTTP_CODE);
print_r($info);

UPDATED

Look this example. http://www.codediesel.com/php/parallel-curl-execution/

Monday, August 9, 2021
 
Eddas
answered 3 Months ago
91

simple_php_dom.php contains:

define('MAX_FILE_SIZE', 600000);
...
if (empty($contents) || strlen($contents) > MAX_FILE_SIZE)
{
    return false;
}

The second page is over 672000 bytes, so this size check fails. Increase that constant and you should be OK.

Saturday, August 21, 2021
 
letrollpoilu
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :