2015-12-14 11:36
浏览 398

cURL http请求没有返回服务器的响应,但fiddler或firebug网络工具没有

I can send HTTP request via fiddler or firebug network tool and receive server response but I cannot receive the same response via cURL and php; What is wrong?

I opened the URL ( in my browser and searched with a filled "lawyer license number" field with "102", I caught the http request and then wrote the code below to imitate the action once more, but there was no response from server at all.

my code is here:

//echo phpinfo();
// Get cURL resource
$curl = curl_init();

// Set some options - we are passing in a useragent too here
$pf=array('name' => '','family' => '','licenseNumber' => '102','Gender' => '','workState' => '','Province' => '','address' => '');

$headers = array(
    'Accept-Language: en-US,en;q=0.5',
    'Accept-Encoding: gzip, deflate',
    'Cache-Control: no-cache',
    'Content-Type: application/json',
    'X-Requested-With: XMLHttpRequest',
    'Pragma: no-cache',
    'Content-Length: 99',
    'Connection: keep-alive',
    'User-Agent: me');

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_URL, '');
curl_setopt($curl, CURLOPT_USERAGENT, 'ali');
curl_setopt($curl, CURLOPT_POST, 0);
curl_setopt($curl, CURLOPT_POSTFIELDS, $pf);

// Send the request & save response to $resp

    die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));

// Close request to clear up some resources


图片转代码服务由CSDN问答提供 功能建议

我可以通过fiddler或firebug网络工具发送HTTP请求并接收服务器响应但我无法通过cURL收到相同的响应 和PHP; 有什么问题?

我打开了网址( )在我的浏览器中搜索带有“102”的填充“律师许可证号码”字段,我抓住了http请求,然后编写了下面的代码再次模仿动作,但服务器没有回复 所有。


 // echo phpinfo(); 
 //获取 cURL资源
 $ curl = curl_init(); 
 //设置一些选项 - 我们也在这里传递一个useragent 
 $ pf = array('name'=&gt;'','family'=&gt  ;'','licenseNumber'=&gt;'102','gender'=&gt;'','workState'=&gt;'','省'=&gt;'','地址'=&gt;'')  ; 
 $ headers = array(
'Accept-Language:en-US,en; q = 0.5',
'Cache-Control:no-cache  ',
'Content-Type:application / json',
'连接 :keep-alive',
'主持人',\  n'Referer:',
 ncurl_setopt($ curl,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_0); 
curl_setopt($ curl,CURLOPT_HTTPHEADER,$ headers  ); 
; ncurl_setopt($ curl,CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ curl,CURLOPT_URL,'');
curl_setopt($curl,  CURLOPT_USERAGENT,'ali'); 
curl_setopt($ curl,CURLOPT_POST,0); 
curl_setopt($ curl,CURLOPT_POSTFIELDS,$ pf); 
 //发送请求&amp; 将响应保存到$ resp 
 $ resp = curl_exec($ curl); 
print_r(json_decode($ resp)); 
if(!$ resp)
 die('Error:“'。curl_error(  $ curl)。'“ - 代码:'。curl_errno($ curl)); 
curl_close($ curl); 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题