failed to open stream error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
reyes99
Forum Commoner
Posts: 38
Joined: Tue May 22, 2007 10:35 pm

failed to open stream error

Post by reyes99 »

Hi,

I am trying to figure out the Amazon API and I am getting the following error...

file_get_contents(http://ecs.amazonaws.com/onca/xml?Servi ... ssKeyId=ID Goes here=2010-10-01&Operation=ItemSearch&SearchIndex=Books&Keywords=Harry Potter): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /home/www/AmazonTest/SimpleStore.php on line 29

I was researching the error and it said that I should turn this on and I did: allow_url_fopen On in the PHP.ini file When I do a phpinfo() it shows "on" now.

This is where I am getting the error:

Code: Select all

$request=
"http://ecs.amazonaws.com/onca/xml"
. "?Service=AWSECommerceService"
. "&AssociateTag=" . Associate_tag
. "&AWSAccessKeyId=" . Access_Key_ID
. "&Version=" . $Version
. "&Operation=" . $Operation
. "&SearchIndex=" . $SearchIndex
. "&Keywords=" . $Keywords
. "&ResponseGroup=" . $ResponseGroup;
// echo "Request output: " .$request;
//Catch the response in the $response object
$response = file_get_contents($request);
line 29 is the file_get_contents($request);

What else can be causing this???

Thanks
Last edited by reyes99 on Mon Jan 17, 2011 7:40 pm, edited 1 time in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: failed to open stream error

Post by requinix »

Do yourself a favor: edit your post (button in the bottom-right corner) and censor the AWSAccessKeyId you put in the URL.

You need to make sure everything in the URL is encoded properly. For one, you can't use spaces: they need to be either +s or %20s. PHP has a built-in function (two, even) for doing this kind of stuff:

Code: Select all

$request = "http://ecs.amazonaws.com/onca/xml?" + http_build_query(array(
	"Service" => "AWSECommerceService",
	"AssociateTag" => Associate_tag,
	"AWSAccessKeyId" => Access_Key_ID,
	"Version" => $Version,
	"Operation" => $Operation,
	"SearchIndex" => $SearchIndex,
	"Keywords" => $Keywords,
	"ResponseGroup" => $ResponseGroup
));
reyes99
Forum Commoner
Posts: 38
Joined: Tue May 22, 2007 10:35 pm

Re: failed to open stream error

Post by reyes99 »

Thank you I will try that....

Thanks for the editing advise alos...
Post Reply