最新消息: 新版网站上线了!!!

php curl post的方法

/*****
 
phpinfo.php
的内容
var_dump($_POST);
 
 
 
 
 
***/
 
$url = 'http://localhost:8089/phproot/phpinfo.php';
$fields = array(
    'MAX_FILE_SIZE' => 100000,
    'function_name'=>'sum_list',
    'vid'=>808,
    'fid'=>247,
    'unique_id'=>'aaa',
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
echo $fields_string;
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
var_dump($result);//执行结果
//close connection
curl_close($ch);

转载请注明:谷谷点程序 » php curl post的方法