Goodreads Developers discussion

46 views
bugs > php file_get_contents fails

Comments Showing 1-8 of 8 (8 new)    post a comment »
dateUp arrow    newest »

message 1: by Bruce (new)

Bruce Fulton (brucefulton) | 9 comments I'm getting the following message:
[function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 using some simple php, as follows:

$request="http://www.goodreads.com/book/title?t...

$response=file_get_contents($request);

I've verified that $request works when manually entered into a browser. Why might I be getting a 400 error and what might be the workaround?


message 2: by Michael (new)

Michael Economy (michaeleconomy) Can you try doing wget or curl? (cookies might be messing with this in the browser)


What's the response body?


message 3: by Bruce (new)

Bruce Fulton (brucefulton) | 9 comments Michael wrote: "Can you try doing wget or curl? (cookies might be messing with this in the browser)


What's the response body?"

$response is blank because the function fails with the 400 error. I'm going to try curl but am having some issues getting it installed on my server VM. I may have to upgrade the OS first.


message 4: by Michael (new)

Michael Economy (michaeleconomy) Ok, thanks for trying that.

Can you email me a sample url containing your key to support@goodreads.com (mention my name).

That would help me diagnose a little more.


message 5: by Bruce (new)

Bruce Fulton (brucefulton) | 9 comments Michael wrote: "Ok, thanks for trying that.

Can you email me a sample url containing your key to support@goodreads.com (mention my name).

That would help me diagnose a little more."


Done. Should be able to test curl tomorrow.


message 6: by Bruce (new)

Bruce Fulton (brucefulton) | 9 comments Michael wrote: "Ok, thanks for trying that.

Can you email me a sample url containing your key to support@goodreads.com (mention my name).

That would help me diagnose a little more."

Server upgrade was fairly painless; once curl was installed, it works. For future reference there is a drop-in function replacement for file_get_open at http://snipplr.com/view/51161/basic-c.... I think based one some other reading while waiting for the server to upgrade is that is likely the agent setting, which spoofs the web service into thinking it is a browser doing the calling. Strictly speaking, that shouldn't be necessary. But curl facilitates this parameter. At least that's my guess. File_get_open should work.


message 7: by Michael (new)

Michael Economy (michaeleconomy) Ok, so everything works now?


message 8: by Bruce (new)

Bruce Fulton (brucefulton) | 9 comments Michael wrote: "Ok, so everything works now?"
Yes, with cURL. Still curious about file_get_contents and the 400 error because I see that popping up with the facebook api too, but since cURL works, I'm moving on. Thanks!


back to top