Two Methods for php POST submission Simulation

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.