CURLOPT_HTTPHEADER:
一个用来设置HTTP头字段的数组。使用如下的形式的数组进行设置: array('Content-type: text/plain', 'Content-length: 100')
<?phpfunction getwebcontent($url){
$ch = curl_init()
$data = array (
'ap' => '2',
'c1' => '4',
'c2' => '4',
'g_w' => '0100',
'dd' => '0',
'h' => '8',
'iasign' => 'bedvkt2gyd9vkgrx',
'pp' => '200',
)
$headers['X-rvt'] = 'IA401004bedvkt2gyd9vkgrx82lIsT'
$headers['Referer'] = 'http://www.benmi.com/IA.html?c1=4&c2=4&g_w=0100&h=1'
$headers['Accept-Language'] = 'zh-CN,zhq=0.8,en-USq=0.5,enq=0.3'
$headers['Cookie'] = 'iasign=bedvkt2gyd9vkgrx'
$timeout = 20
curl_setopt ($ch, CURLOPT_URL, $url)
curl_setopt ($ch, CURLOPT_POST, 1)
curl_setopt ($ch, CURLOPT_VERBOSE , 0)
curl_setopt ($ch, CURLOPT_HEADER, 1)
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0)
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout)
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0)
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data )
curl_setopt ($ch, CURLOPT_HTTPHEADER , $headers)
$contents = curl_exec($ch)
curl_close($ch)
return $contents
}
$c = getwebcontent('http://www.benmi.com/Ashx/IAPageAjax.ashx')
print($c)
获取请求头信息,可以在curl_exec函数执行前,添加代码curl_setopt($ch,CURLINFO_HEADER_OUT,true)在curl_exec函数执行后,通过 curl_getinfo($ch,CURLINFO_HEADER_OUT) 来获取curl执行请求的请求数据。获取响应头信息,可以在curl_exec函数执行前,添加代码 curl_setopt($ch, CURLOPT_HEADER, true)curl_setopt($ch, CURLOPT_NOBODY,true)之后 通过curl_exec函数来获取响应头信息。获取设置 curl_setopt($ch, CURLOPT_NOBODY,false)然后对curl_exec获取的值通过\r\n\r\n进行分割截取第一部分即为响应头信息。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)