dongyinting3179 2015-12-14 11:36
浏览 414
已采纳

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 (http://search.icbar.org) 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:

<?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);

?>
  • 写回答

1条回答 默认 最新

  • duanfen2349 2015-12-14 11:58
    关注

    As you are sending json request to the server, convert your array into json object.

    $pf = json_encode($pf);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀