using curl to peform post
| From: | Brent Clark | Date: | Mon, 05 Dec 2005 07:17:45 +0000 |
| Subject: | using curl to peform post | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-226856@lists.php.net to get a copy of this message | ||
Hi all
I have need to simulate the role of a web browser by submitting the following code.
<form name="form1" action="propsearch.pl" method="post">
<textarea rows="12" cols="70" name="msg">GREENc</textarea>
<input type="submit" value="Submit">
</form>
Heres my PHP code that got from the curl function.
<?php
$url = "www.example.com";
$page = "/cgi-bin/ecco/scripts/h2h/glo/propsearch.pl";
$post_string = "msg=GREE01";
$header = "POST ".$page." HTTP/1.0 ";
$header .= "MIME-Version: 1.0 ";
$header .= "Content-type: application/PTI26 ";
$header .= "Content-length: ".strlen($post_string)." ";
$header .= "Content-transfer-encoding: text ";
$header .= "Request-number: 1 ";
$header .= "Document-type: Request ";
$header .= "Interface-Version: Test 1.4 ";
$header .= "Connection: close ";
$header .= $post_string;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
$data = curl_exec($ch); if (curl_errno($ch)) {
print curl_error($ch);
} else {
curl_close($ch);
}
print $data;
?>
Any assistant would gratefully be appreciated.
Kind Regards
Brent Clark