curL on wamp不工作

Tha*_*Kov 5 php curl

我正在使用公司编写的php客户端来访问他们的Web服务.客户端非常全面,包括从Web服务端点生成的XML响应中填充的类.

当我在适当的网络服务器上运行它时,它的工作原理.但是,当我在本地使用它时,它会抛出一个没有收到数据的错误.

我已经检查了所有StackOverflow,我通常会找到我的问题的答案,但这个让我疯了!

这是httpPost函数(作为他们提供的php客户端的一部分编写):

private function _httpPost(array $parameters)
    {
        $query = $this->_getParametersAsString($parameters);
        $url = parse_url ($this->_config['ServiceURL']);
        $scheme = '';

        switch ($url['scheme']) {
            case 'https':
                $scheme = 'https://';
                $port = $port === null ? 443 : $port;
                break;
            default:
                $scheme = '';
                $port = $port === null ? 80 : $port;
        }

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $scheme . $url['host'] . $url['path']);
        curl_setopt($ch, CURLOPT_PORT, $port);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_USERAGENT, $this->_config['UserAgent']);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
        curl_setopt($ch, CURLOPT_HEADER, true); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);


        if ($_config['ProxyHost'] != null && $_config['ProxyPort'] != -1)
        {
            curl_setopt($ch, CURLOPT_PROXY, $_config['ProxyHost'] . ':' . $_config['ProxyPort']);
        }
        $response = "";
        $response = curl_exec($ch);
        $response = str_replace("HTTP/1.1 100 Continue\r\n\r\n", "", $response);


        curl_close($ch);

        list($other, $responseBody) = explode("\r\n\r\n", $response, 2);
        $other = preg_split("/\r\n|\n|\r/", $other);
        list($protocol, $code, $text) = explode(' ', trim(array_shift($other)), 3);

        return array ('Status' => (int)$code, 'ResponseBody' => $responseBody);
    }
Run Code Online (Sandbox Code Playgroud)

顺便说一句,我的卷曲扩展是活跃的,我甚至做了一个简单的测试来成功获取google.com.

Sha*_*yam 9

我的猜测是它与你所使用的VERIFYPEER选项有关,通常没有配置wamp上的curl支持它(CA证书包),所以默认情况下它会拒绝所有SSL证书作为无法验证.

尝试替换它(只有在您的localhost上进行测试时,您希望在使用服务器时将其设置为ON):

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
Run Code Online (Sandbox Code Playgroud)

祝好运.

编辑:
这取自curl的"服务器SSL证书详细信息":

如果远程服务器使用自签名证书,如果未安装CA证书捆绑包,则服务器使用由CA签名的证书(未包含在您使用的捆绑包中)或远程主机是冒名顶替者模拟您最喜欢的网站,并且您想要从此服务器传输文件,请执行以下操作之一:

1)告诉libcurl 验证对等体.使用libcurl,您可以使用curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,FALSE)禁用它; 使用curl命令行工具,可以使用-k/ - insecure禁用它.

2)获取可以验证远程服务器的CA证书,并在连接时使用正确的选项指出此CA证书以进行验证.对于libcurl黑客:curl_easy_setopt(curl,CURLOPT_CAPATH,capath); 使用curl命令行工具:--cacert [file]