examle one :
function Post($url, $data)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, FALSE);//不抓取头部信息。只返回数据
curl_setopt($curl, CURLOPT_TIMEOUT,1000);//超时设置
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);//1表示不返回bool值
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));//重点
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
$response = curl_exec($curl);
if (curl_errno($curl)) {
return curl_error($curl);
}
curl_close($curl);
return $response;
//header('Location:'.$response['data']['url']);
}
—————————————
example two:
/**
* php curl中x-www-form-urlencoded 请求数据
* @param string $data 请求数据
* @param string $url 请求地址
* @return boolean [description]
*/
function curPost($url,$data)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);//不抓取头部信息。只返回数据
curl_setopt($curl, CURLOPT_TIMEOUT,1000);//超时设置
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//1表示不返回bool值
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));//重点
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
$response = curl_exec($curl);
if (curl_errno($curl)) {
return curl_error($curl);
}
curl_close($curl);
return $response;
}