Site not understanding request sent by fputs?

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
daved27
Forum Newbie
Posts: 3
Joined: Tue Dec 30, 2008 3:35 pm

Site not understanding request sent by fputs?

Post by daved27 »

Hi, I'm trying to write a script that will search for specific information from a php script that is serves xml from a website, and everything is working well except for one thing.

The website uses /options to look at previous pages. I'm not sure how to describe this, so I'll give an example: script.php?xml=true&/302 - would be opening page 302. However, when I type this into my script (using fputs($fc, "GET http://x.com/script.php?xml=true&/302 HTTP/1.1\r\nHost: x.com\r\n\r\n")), I get served the default page, as if the server isn't understanding the request.

If anyone could offer any ideas as to why that would be I'd be very grateful, as I'm relatively new to php, and don't see why this shouldn't be working.

Thanks, Dave
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Site not understanding request sent by fputs?

Post by requinix »

Don't forge headers when you don't know what you're doing.

Code: Select all

$xml = file_get_contents("http://x.com/script.php?xml=true&/302");
daved27
Forum Newbie
Posts: 3
Joined: Tue Dec 30, 2008 3:35 pm

Re: Site not understanding request sent by fputs?

Post by daved27 »

Thanks, that works brilliantly. Can I ask for a more detailed explanation of what that function does that my script didn't, and how it did it? If it's just to do with headers, how did it find out which ones to send? etc.

I just want a deeper understanding of what is going on instead of always having to rely on functions that are already available. Thanks for the help :)

Dave

[EDIT] - Out of curiosity, I examined the headers/responses sent by the respective code.

Original code (fails):
Image

Provided code (works):
Image

The only difference I can see is that the server closes the connection on the working code, but I can't see why, as the submitted headers appear to be identical. If anyone has any ideas as to why that may be, please let me know.

Thanks, Dave
Post Reply