小编ale*_*kov的帖子

Curl:显示所有PHP本地主机站点的“无法解析域名”错误

今天,我的cURL开始向我显示此错误,Could not resolve: {local-domain.test} (domain name not found) 如果我尝试从外部链接获取某些信息,则一切正常,但是本地站点无法正常工作。

所以,这是我的代码

public function send($type, $url, $data)
    {
        $type = strtolower($type);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        if ($type == 'post') {
            $urlWithData = http_build_query($data);
            curl_setopt($ch, CURLOPT_POST, count($data));
            curl_setopt($ch, CURLOPT_POSTFIELDS, $urlWithData);
        }

        $result = curl_exec($ch);
        $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

        $out = new \stdClass();
        $out->status = $status;
        $out->body = json_decode($result, true);

        return $out;
    }
Run Code Online (Sandbox Code Playgroud)

如果我将该主机添加到我的/ etc / hosts /文件中,那么所有主机都将开始工作,但是我拥有大量的域,并且在更新PHP之前,我都可以正常工作。我正在使用dnsmasq作为动态主机解析工具。

  • 操作系统:MacOs High …

php dnsmasq curl

8
推荐指数
1
解决办法
801
查看次数

标签 统计

curl ×1

dnsmasq ×1

php ×1