Re: http POST

From: Date: Sat, 08 Apr 2000 03:45:21 +0000
Subject: Re: http POST
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-17733@lists.php.net to get a copy of this message
Hello Pete, On 07-Apr-00 17:47:18, you wrote: >I need some help with HTTP transactions. I am opening a socket and using >fputs to send a request to a URL. Like such: > // try to connect to Web server > $connection = fsockopen("www.somedomain.com", > 80, &$error_number, &$error_description); > // send transaction > fputs($connection, "GET /test/testOAS?123\r\n"); > fputs($connection, "\r\n"); >this works fine. I attempted to simply change the method to a POST and send >the data on another line but it ignores the data sent. > // try to connect to Web server > $connection = fsockopen("www.somedomain.com", > 80, &$error_number, &$error_description); > // send transaction > fputs($connection, "POST /test/testOAS\r\n"); > fputs($connection, "123\r\n"); > fputs($connection, "\r\n"); >This hit the URL but the data attached, "123", was ignored. What is the >correct syntax for appending data to a post transaction. The posted data is part of the request message body. You should leave an empty line before it. You are missing the field names. You also need to set the Content-Type: header to application/x-www-form-urlencoded and set the Host: header with the server host name in case the server is hosted in a virtual server. Anyway, you may like to try this PHP HTTP client request class that already comes with complete example on how to emulate POST requests. http://phpclasses.UpperDesign.com/browse.html/package/3 Regards, Manuel Lemos Web Programming Components using PHP Classes. Look at: http://phpclasses.UpperDesign.com/?user=mlemos@acm.org -- E-mail: mlemos@acm.org URL: http://www.mlemos.e-na.net/ PGP key: http://www.mlemos.e-na.net/ManuelLemos.pgp --

« previous php.dev (#17733) next »