php curl提交头部信息错误
<?phpfunctiongetwebcontent($url){$ch=curl_init();$data=array('ap'=>'2','c1'=>'4','c2'...
<?php
function 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,zh;q=0.8,en-US;q=0.5,en;q=0.3';
$headers['Cookie'] = 'iasign=bedvkt2gyd9vkgrx;';
$headerArr = array();
foreach( $headers as $n => $v ) {
$headerArr[] = $n .':' . $v;
}
$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 , $headerArr);
$contents = curl_exec($ch);
curl_close($ch);
return $contents;
}
$c=getwebcontent('http://www.benmi.com/Ashx/IAPageAjax.ashx');
print($c);
?>
求帮忙看下,哪里有问题,另:上面这些参数用python是可以读出数据(json)来的 展开
function 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,zh;q=0.8,en-US;q=0.5,en;q=0.3';
$headers['Cookie'] = 'iasign=bedvkt2gyd9vkgrx;';
$headerArr = array();
foreach( $headers as $n => $v ) {
$headerArr[] = $n .':' . $v;
}
$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 , $headerArr);
$contents = curl_exec($ch);
curl_close($ch);
return $contents;
}
$c=getwebcontent('http://www.benmi.com/Ashx/IAPageAjax.ashx');
print($c);
?>
求帮忙看下,哪里有问题,另:上面这些参数用python是可以读出数据(json)来的 展开
1个回答
展开全部
CURLOPT_HTTPHEADER:
一个用来设置HTTP头字段的数组。使用如下的形式的数组进行设置: array('Content-type: text/plain', 'Content-length: 100')
<?php
function 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,zh;q=0.8,en-US;q=0.5,en;q=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);
追问
你有木在机子上跑一跑?这个是400错误,Invalid Header
帮忙研究下,我实在是懵了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询