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.
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
The 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
The 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 );