cURL 错误 - “无法解析主机:www.bbb.org(;没有请求类型的数据记录”

发布于 2024-09-10 03:37:37 字数 2037 浏览 0 评论 0原文

我正在尝试访问 http://www.bbb.org/us/ 的数据使用 cURL 查找-Business-Reviews/。现在我使用 HTTPFox 来查看该站点发送哪些数据,并相应地创建一个数组以“POST”到页面。但我在访问第 2,3,4,5 页时遇到问题...

这是数组 -

$array = Array();
 $array['__EVENTTARGET'] = 'ctl12$gc1$s$gridResults$ctl23$pagerLinkButton2';
 $array['__EVENTARGUMENT'] = '';
 $array['__LASTFOCUS'] = '';
 $array['__VIEWSTATEFIELDCOUNT'] = 6;
 $array['__VIEWSTATE']  = $View_state;
 $array['__VIEWSTATE1'] = $View_state1;
 $array['__VIEWSTATE2'] = $View_state2;
 $array['__VIEWSTATE3'] = $View_state3;
 $array['__VIEWSTATE4'] = $View_state4;
 $array['__VIEWSTATE5'] = $View_state5;
 $array['ctl12$qn$quickSearch'] = "";
 $array['ctl12$qn$TextBoxWatermarkExtender1_ClientState'] = "";
 $array['ctl12$gc1$s$txtSearch'] = "tax";
 $array['ctl12$gc1$s$CityTextBox'] = "";
 $array['ctl12$gc1$s$ddlState'] = "";
 $array['ctl12$gc1$s$ZipTextBox'] = 10292; 
 $array['ctl12$gc1$s$ddlSort'] = "SCORE DESC";

但我总是遇到相同的错误 -

“无法解析主机:www.bbb.org(;没有请求类型的数据记录”

这是我正在使用的 cURL 函数

function cURL($url, $header=NULL, $p=NULL) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HEADER, $header);
        curl_setopt($ch, CURLOPT_NOBODY, $header);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        if ($p) {
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $p);
        }
        $result = curl_exec($ch);
        if ($result) {
            return $result;
        } else {
            return curl_error($ch);
        }
        curl_close($ch);
    }

I am trying to access data of http://www.bbb.org/us/Find-Business-Reviews/ with cURL. Now I used HTTPFox to see what data does this site send and accordingly made an array to "POST" to the page. But I am having problem in accessing Page 2,3,4,5...

Here is the array -

$array = Array();
 $array['__EVENTTARGET'] = 'ctl12$gc1$s$gridResults$ctl23$pagerLinkButton2';
 $array['__EVENTARGUMENT'] = '';
 $array['__LASTFOCUS'] = '';
 $array['__VIEWSTATEFIELDCOUNT'] = 6;
 $array['__VIEWSTATE']  = $View_state;
 $array['__VIEWSTATE1'] = $View_state1;
 $array['__VIEWSTATE2'] = $View_state2;
 $array['__VIEWSTATE3'] = $View_state3;
 $array['__VIEWSTATE4'] = $View_state4;
 $array['__VIEWSTATE5'] = $View_state5;
 $array['ctl12$qn$quickSearch'] = "";
 $array['ctl12$qn$TextBoxWatermarkExtender1_ClientState'] = "";
 $array['ctl12$gc1$s$txtSearch'] = "tax";
 $array['ctl12$gc1$s$CityTextBox'] = "";
 $array['ctl12$gc1$s$ddlState'] = "";
 $array['ctl12$gc1$s$ZipTextBox'] = 10292; 
 $array['ctl12$gc1$s$ddlSort'] = "SCORE DESC";

But I am always getting the same error -

"Could not resolve host: www.bbb.org(; No data record of requested type"

Here is the cURL function I am using

function cURL($url, $header=NULL, $p=NULL) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HEADER, $header);
        curl_setopt($ch, CURLOPT_NOBODY, $header);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        if ($p) {
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $p);
        }
        $result = curl_exec($ch);
        if ($result) {
            return $result;
        } else {
            return curl_error($ch);
        }
        curl_close($ch);
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

日裸衫吸 2024-09-17 03:37:37

您看这里引用的 URL 没有什么问题吗? :)

Could not resolve host: www.bbb.org(;

Do you see nothing wrong with the URL quoted here? :)

Could not resolve host: www.bbb.org(;
菩提树下叶撕阳。 2024-09-17 03:37:37

可能与您的问题没有任何关系,但是:

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POST, 1);

是重复的。通过设置 CURLOPT_POST,您已经告诉curl您正在发布帖子。 CUSTOMREQUEST 用于执行不常见的 HTTP 请求,例如“HEAD”,对此不存在标准 CURL 函数调用。

Probably not really anything to do with your problem, but:

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POST, 1);

is duplicative. By setting CURLOPT_POST, you're already telling curl you're doing a post. CUSTOMREQUEST is for doing uncommon HTTP requests, like 'HEAD', for which a standard CURL function call doesn't exist.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文