POST to YAWS using fsockopen

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
selmab
Forum Newbie
Posts: 3
Joined: Wed Jun 22, 2005 6:10 am

POST to YAWS using fsockopen

Post 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
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post 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.
selmab
Forum Newbie
Posts: 3
Joined: Wed Jun 22, 2005 6:10 am

Post 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?
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post 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).
selmab
Forum Newbie
Posts: 3
Joined: Wed Jun 22, 2005 6:10 am

Post by selmab »

Yeah a GET worked :S
Thanks.

Best regards,

Selma
Post Reply