Page 1 of 1

fsock - Getting file from POST

Posted: Wed Jan 30, 2008 8:12 am
by lolao
Hi.

I've been puzzling around with a method, and can't seem to get it working.

What I want to do, is to connect to a page (secure / SSL), login to an account and then get the content of a remote file, which is automatically generated by posting a form.

Most of it works already, but when my script has posted the login (which is successfully carried out) I can't seem to get/download this file I want, from the account front page.
Problem is that the file is generated (XML) when you click on a <button>, which means I don't really know the exact location of the file.
So I've tried submitting/posting the form <button> the same way I've done it with the login, and that seems to be working, but how do I get the content of the generated XML file? Normally, I mean, a download popup would appear if you submitted/posted the <button> through a web browser, but how do I receive the content with my script and maybe place it in a variable ($XML_fileContent).

I've been intensively trying to solve this problem and get it to work for three days now, but really can't seem to figure out a solution. I thought of this forum and I hope that someone can help me out.

[Using fsockopen, no CURL]

Any suggestions? Anyone tried this before who actually made it work?

Help is appreciated! Thanks. :)

Re: fsock - Getting file from POST

Posted: Wed Jan 30, 2008 11:19 am
by Christopher
To cause files to download, rather than display -- use the header() function to set the MIME type, size, etc. Check the documentation for the header() function for examples.

Re: fsock - Getting file from POST

Posted: Wed Jan 30, 2008 11:56 am
by lolao
Thanks for the answer, but actually the file isn't even displayed. There doesn't seem to be any information indicating the file's path, so I'd have to be able to make a script automatically accept a download dialog OR simply paste the content of the requested file in my document somehow.

Thanks anyway.

Can anyone help any further?

Re: fsock - Getting file from POST

Posted: Wed Jan 30, 2008 4:35 pm
by Mordred
If I understand correctly what you're doing, you submit a post form with sockets and raw HTTP, and the form is supposed to return a file download, right? The file contents will come in the body of the HTTP response. Look at the headers sent for details how to obtain the data. Most probably it will be a multipart message, meaning you'll have to correctly manage the parts and then glue the file together. Consult the HTTP/1.1 RFC 2616 (yay, got it from memory, I'm not that rusty after all ;) ) for details. A file download is really not different from a page download.