//set POST variables
$fields = array(
'firstname' => 'Joe',
'lastname' => 'Smith'
);
//urlify the data for the POST
$fieldsString = join('&', array_map('urlencode', $fields);
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, 'http://somewebsite.com');
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fieldsString);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
// view the results
echo $result;
1 回答
以下是使用cURL发出POST请求的方法: