This article provides a detailed analysis of the two methods for php POST submission. For more information, see
This article provides a detailed analysis of the two methods for php POST submission. For more information, see
1. Use the curl Function
The Code is as follows:
$ Post_data = array ();
$ Post_data ['clientname'] = "test08 ";
$ Post_data ['clientpasswd'] = "test08 ";
$ Post_data ['submit '] = "submit ";
$ Url = 'HTTP: // xxx. xx/xxx/top. php ';
$ O = "";
Foreach ($ post_data as $ k => $ v)
{
$ O. = "$ k =". urlencode ($ v )."&";
}
$ Post_data = substr ($ o, 0,-1 );
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_POST, 1 );
Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
Curl_setopt ($ ch, CURLOPT_URL, $ url );
// To support cookies
Curl_setopt ($ ch, CURLOPT_COOKIEJAR, 'cookie.txt ');
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_data );
$ Result = curl_exec ($ ch );
Ii. fsockopen
The Code is as follows:
$ URL = '';
$ Post_data ['clientname'] = "test08 ";
$ Post_data ['clientpasswd'] = "test08 ";
$ Post_data ['submit '] = "too many temporary connections ";
$ Referrer = "";
// Parsing the given URL
$ URL_Info = parse_url ($ URL );
// Building referrer
If ($ referrer = "") // if not given use this script as referrer
$ Referrer =
{1}
SERVER ["SCRIPT_URI"]; // making string from $ dataforeach ($ post_data as $ key => $ value) $ values [] = "$ key = ". urlencode ($ value); $ data_string = implode ("&", $ values); // Find out which port is needed-if not given use standard (= 80) if (! Isset ($ URL_Info ["port"]) $ URL_Info ["port"] = 80 ;//
Building POST-request: $ request. = "POST ". $ URL_Info ["path"]. "HTTP/1.1 \ n"; $ request. = "Host :". $ URL_Info ["host"]. "\ n"; $ request. = "Referer: $ referrer \ n"; $ request. = "Content-type: application/x-www-form-urlencoded \ n"; $ request. = "Content-length :". strlen ($ data_string ). "\ n"; $ request. = "Connection:
Close \ n "; $ request. = "\ n"; $ request. = $ data_string. "\ n"; $ fp = fsockopen ($ URL_Info ["host"], $ URL_Info ["port"]); fputs ($ fp, $ request); while (! Feof ($ fp) {$ result. = fgets ($ fp, 128);} fclose ($ fp );
Snoopy class (2)
Sourceforge.net/projects/snoopy/
? Wp-DES/class-snoopy.php.htm
HTTP class (1, 2)
PEAR HTTP_Request
Popularity: 70%
, US space, Hong Kong server, Hong Kong Space