Page 1 of 1

POST to YAWS using fsockopen

Posted: Wed Jun 22, 2005 6:25 am
by selmab
Hi,

I am trying to do a POST to a form which resides on a YAWS server.
This is the code I use to send the POST:

Code: Select all

$host="www.myserver.com";
       $path="/webcmd/getData";
       $query="id=".$var."&force=true";

       $post = "POST $path HTTP/1.1\r\n";
	$post .= "Host: $host\r\n";
	$post .= "Content-type: application/x-www-form-urlencoded\r\n";
	$post .= "Content-length: ".strlen($query)."\r\n\r\n";
	$post .= "$query\r\n";
	$post .= "Connection: close \r\n\r\n";
This is the response I get from the server:

HTTP/1.1 200 OK
Server: Yaws/1.31 Yet Another Web Server
Date: Wed, 22 Jun 2005 10:53:26 GMT
Content-Type: text/plain
Transfer-Encoding: chunked

1B
1 Missing id parameter

I am not all that experienced with sending POST requests through sockets, but I have done this successfully in the past (although only with Apache).

Do you see any errors in my code? Does YAWS require some other format than this?
If you don't know exactly what's going on I'd also appreciate pointers on where I can read something related to my problem.

TIA,

Selma

Posted: Wed Jun 22, 2005 6:35 am
by Syranide
I believe ID is missing because your post-query is improper, I'm not very fond of them myselves so I don't know how they work straight out, but, as it is missing "id" it is pretty logical that it could be the problem.

Posted: Wed Jun 22, 2005 6:48 am
by selmab
Executing this http://www.myserver.com/webcmd/getData?id=1&force=true from a web browser returns the result that I need.

I'm not sure what you mean when you say "improper". Do you know what exactly might be improper?

Posted: Wed Jun 22, 2005 8:03 am
by Syranide
if that works for you, then you don't need to do POST, just do a GET instead, much simpler if the server allows it (which is does for you).

Posted: Wed Jun 22, 2005 8:49 am
by selmab
Yeah a GET worked :S
Thanks.

Best regards,

Selma