| | |
HTTP POST request from PHP
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
Here's my predicament. I Have managed to send and retrieve some HTTP requests using the GET method successfully using the following code:
I have tried a few times to send some data via POST but haven't had any luck. (I haven't had any trace of the POST data getting through)
(set up a form to submit some GET and POST data to
Any ideas?
php Syntax (Toggle Plain Text)
function send_to_host($host,$method,$path='/',$data='',$useragent=0){ // Supply a default method of GET if the one passed was empty if (empty($method)) { $method = 'GET'; } $method = strtoupper($method); $fp = fsockopen($host, 80) or die("Unable to open socket"); fputs($fp, "$method $path HTTP/1.1\r\n"); fputs($fp, "Host: $host\r\n"); fputs($fp, "Content-type: application/x-www-form- urlencoded\r\n"); if ($method == 'POST') fputs($fp, "Content-length: " . strlen($data) . "\r\n"); if ($useragent) fputs($fp, "User-Agent: MSIE\r\n"); fputs($fp, "Connection: close\r\n\r\n"); if ($method == 'POST') fputs($fp, $data); while (!feof($fp)) $buf .= fgets($fp,128); fclose($fp); return $buf; } send_to_host('humbot.freewebhostingpro.com','GET','/index.php?a=5',''); //sent from localhost
I have tried a few times to send some data via POST but haven't had any luck. (I haven't had any trace of the POST data getting through)
(set up a form to submit some GET and POST data to
humbot.freewebhostingpro.com/index.php and the page will display that data)Any ideas?
★ "If your not having fun, your doing something wrong." - Humbug
★ Did I help you out? Did I piss you off? Add to my reputation!
★ The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
★ Did I help you out? Did I piss you off? Add to my reputation!
★ The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
•
•
Join Date: Dec 2007
Posts: 113
Reputation:
Solved Threads: 17
you are passing only three parameters. For post, your third parameter should be only the php script that processes the request(without the querystring parameters) and the fourth parameter should be the "querystring" data. Try:
PHP Syntax (Toggle Plain Text)
send_to_host('humbot.freewebhostingpro.com','POST','/index.php','a=5');
Notice how line 24 of my code includes "GET" and not "POST"? That's the call I used to (successfully) send a GET request (as the English above clearly states).
I have slightly modified the code making up that function from the code I got off the net so I understand what needs to go in which parameter.
I have tried the line you suggested an a few similar (even with the original code) but none have shown me that my POST data was received.
I have slightly modified the code making up that function from the code I got off the net so I understand what needs to go in which parameter.
I have tried the line you suggested an a few similar (even with the original code) but none have shown me that my POST data was received.
★ "If your not having fun, your doing something wrong." - Humbug
★ Did I help you out? Did I piss you off? Add to my reputation!
★ The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
★ Did I help you out? Did I piss you off? Add to my reputation!
★ The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
•
•
Join Date: Dec 2007
Posts: 113
Reputation:
Solved Threads: 17
>>Notice how line 24 of my code includes "GET" and not "POST"? That's the call I used to (successfully) send a GET request (as the English above clearly states).
Yes, I can see that, but it is NOT clear if you were doing this:
which is NOT the correct way to call it. The parameters should not be appended to the uri. Instead you need:
On another note, the source of the problem is:
there should be NO space between the hyphen and urlencoded. It should be:
Yes, I can see that, but it is NOT clear if you were doing this:
PHP Syntax (Toggle Plain Text)
send_to_host('humbot.freewebhostingpro.com','POST','/index.php?a=5','');
which is NOT the correct way to call it. The parameters should not be appended to the uri. Instead you need:
PHP Syntax (Toggle Plain Text)
send_to_host('humbot.freewebhostingpro.com','POST','/index.php','a=5');
On another note, the source of the problem is:
PHP Syntax (Toggle Plain Text)
fputs($fp, "Content-type: application/x-www-form- urlencoded\r\n");
there should be NO space between the hyphen and urlencoded. It should be:
PHP Syntax (Toggle Plain Text)
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
Thanks for that last bit of info, it has actually made my requests successful. You've been a big help because HTTP headers is something I have only briefly read over.
Cheers.
Cheers.
★ "If your not having fun, your doing something wrong." - Humbug
★ Did I help you out? Did I piss you off? Add to my reputation!
★ The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
★ Did I help you out? Did I piss you off? Add to my reputation!
★ The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
Sorry, way to long ago to remember or find out.
★ "If your not having fun, your doing something wrong." - Humbug
★ Did I help you out? Did I piss you off? Add to my reputation!
★ The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
★ Did I help you out? Did I piss you off? Add to my reputation!
★ The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
![]() |
Similar Threads
- Post Bulk Data In AJAX request (JavaScript / DHTML / AJAX)
- A PHP REST POST request? (PHP)
- how to assign javascript variable to php variable (PHP)
- Parent/Child Windows References (JavaScript / DHTML / AJAX)
- Can a text link pass php variables? (PHP)
- wiki pages (PHP)
- error message when shutting down, startup page stuck to http://dr-search4u.com/ind... (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: Decrypt Invisionfree Passwords
- Next Thread: PHP access restriction
| Thread Tools | Search this Thread |
# 5.2.10 alexa apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date directory display dissertation dropdown dynamic echo echo$_get[x]changingitintovariable... email encode error fairness file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery newsletters oop open paypal pdf persist php problem provider query radio random recursion remote rss script search server sessions sms sockets source space spam sql syntax system table tutorial update upload url validator variable video web youtube





