Two methods for simulating POST data transmission in php:
Source: Internet
Author: User
In php, the two methods of simulating POST data transmission are shared. sometimes you need to simulate and submit data for easy data collection. For more information, see. Method 1
Copy codeThe code is as follows:
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, "http: // 192.168.1.135/turntable/get_jump.php ");
Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ array );
Curl_exec ($ ch );
Curl_close ($ ch );
Method 2
Copy codeThe code is as follows:
$ Data ['uid'] = $ this-> uid;
$ Data ['efforts'] = $ res ['efforts'];
$ Data ['breakpass'] = $ res ['breakpass'];
$ Data ['target'] = $ res ['target'];
$ Str = '';
Foreach ($ data as $ k => $ v ){
If (is_array ($ v )){
Foreach ($ v as $ kv => $ vv ){
$ Str. = '&'. $ k. '['. $ kv. '] ='. urlencode ($ vv );
}
} Else {
$ Str. = '&'. $ k. '='. urlencode ($ v );
}
}
$ Context =
Array ('http' =>
Array ('method' => 'post ',
'Header' => 'Content-type: application/x-www-form-urlencoded'. "\ r \ n ".
'User-Agent: Manyou api php Client 0.1 (non-curl) '. phpversion (). "\ r \ n ".
'Content-length: '. strlen ($ str ),
'Content' => $ str ));
$ Contextid = stream_context_create ($ context );
$ Sock = fopen ('http: // 192.168.1.135/turntable/get_jump.php', 'R', false, $ contextid );
If ($ sock ){
$ Result = '';
While (! Feof ($ sock )){
$ Result. = fgets ($ sock, 4096 );
}
Fclose ($ sock );
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.