[英]cURL http request returns no response from server but fiddler or firebug network tool does
我可以通過提琴手或螢火蟲網絡工具發送HTTP請求並接收服務器響應,但不能通過cURL和php接收相同的響應; 怎么了?
我在瀏覽器中打開了URL( http://search.icbar.org ),並使用“ 102”填充了“律師執照號碼”字段,並捕獲了http請求,然后編寫了下面的代碼來模擬一次操作更多信息,但服務器完全沒有響應。
我的代碼在這里:
<?php
//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',
'Host: search.icbar.org',
'Referer: http://search.icbar.org/',
'User-Agent: me');
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_URL, 'http://search.icbar.org/Handler/Law.ashx?Method=mGetLawyers');
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
$resp=curl_exec($curl);
print_r(json_decode($resp));
if(!$resp)
{
die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
}
// Close request to clear up some resources
curl_close($curl);
?>
當您向服務器發送json請求時,將數組轉換為json對象。
$pf = json_encode($pf);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.