方式一:用file_get_contents来模拟请求:
$url = 'http://www.dybcotton.com/search/express';
search参数需要我们自己去抓包获得
常用抓包工具下载地址:http://www.fiddler2.com/dl/Fiddler2Setup.exe ;
function file_get_contents_post($url = '', $post_data = array()) {
$options = array(
'http' => array(
'method' => 'POST',
'content' => http_build_query($post_data),
),
);
$result = file_get_contents($url, false, stream_context_create($options));
return $result;
}
方式二:用curl来模拟请求:
$url = 'http://www.dybcotton.com/search/express';
$post_data['search'] ='65311151191';
$res = file_get_contents_post($url, $post_data);
print_r($res);
function request_post($url = '', $post_data = array()) {
if (empty($url) || empty($post_data)) {
return false;
}
$o = "";
foreach ( $post_data as $k => $v )
{
$o.= "$k=" . urlencode( $v ). "&" ;
}
$post_data = substr($o,0,-1);
$postUrl = $url;
$curlPost = $post_data;
$ch = curl_init();//初始化CURL
curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
curl_setopt($ch, CURLOPT_HEADER, 0);//设置HEADER
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_POST, 1);//POST提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec($ch);//运行CURL
curl_close($ch);
return $data;
}$url = 'http://www.dybcotton.com/search/express';
$post_data['search'] ='65311151191';
$res = request_post($url, $post_data);
print_r($res); search参数需要我们自己去抓包获得
常用抓包工具下载地址:http://www.fiddler2.com/dl/Fiddler2Setup.exe ;