gpt4 book ai didi

php - curl 错误 :140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

转载 作者:太空宇宙 更新时间:2023-11-03 14:30:46 62 4
gpt4 key购买 nike

我正在尝试将代理和 SSL 证书与 CURL 一起使用,但出现错误。

这是 CURL 代码:

//Website
$url = 'https://www.stubhub.com';

//Curl
$curl=curl_init();

//SSL
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, true );
curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 2 );
curl_setopt( $curl, CURLOPT_CAINFO, 'C:\xampp\cacert.pem' );

curl_setopt( $curl, CURLOPT_URL,trim( $url ) );
curl_setopt($curl, CURLOPT_REFERER, $url);
curl_setopt( $curl, CURLOPT_AUTOREFERER, true );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $curl, CURLOPT_FAILONERROR, true );
curl_setopt( $curl, CURLOPT_HEADER, false );
curl_setopt( $curl, CURLINFO_HEADER_OUT, false );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_BINARYTRANSFER, true );
curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 0 );
curl_setopt( $curl, CURLOPT_TIMEOUT, 0 );
curl_setopt( $curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36' );

//Proxy
curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($curl, CURLOPT_PROXY, '177.190.147.241:41545');
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt ($curl, CURLOPT_PORT , 80);

curl_setopt($curl, CURLOPT_COOKIEFILE,__DIR__."/cookie.txt");
curl_setopt( $curl, CURLOPT_MAXREDIRS, 10 );
curl_setopt( $curl, CURLOPT_ENCODING, '' );

curl_setopt( $curl, CURLOPT_VERBOSE, true );
curl_setopt( $curl, CURLOPT_NOPROGRESS, true );
curl_setopt( $curl, CURLOPT_STDERR, $vbh );

我得到以下响应:

* Rebuilt URL to: https://www.stubhub.com/
* Trying 177.190.147.241...
* TCP_NODELAY set
* Connected to 177.190.147.241 (177.190.147.241) port 41545 (#0)
* Establish HTTP proxy tunnel to www.stubhub.com:80
> CONNECT www.stubhub.com:80 HTTP/1.1
Host: www.stubhub.com:80
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1
Proxy-Connection: Keep-Alive

< HTTP/1.1 200 OK
<
* Proxy replied OK to CONNECT request
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: C:\xampp\cacert.pem
CApath: none
* error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
* Curl_http_done: called premature == 1
* Closing connection 0
error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

如何解决这个问题?

最佳答案

* Rebuilt URL to: https://www.stubhub.com/

您正在尝试访问 URL https://www.stubhub.com/ - 这意味着端口 443 上的给定主机(默认为 https)协议(protocol)为 https(即基于 TLS 的 HTTP) .

但是,由于未知原因,您明确指定应使用端口 80 而不是端口 443:

curl_setopt ($curl, CURLOPT_PORT , 80);

这意味着它不会连接到主机的 443 端口,而是 80 端口:

* Establish HTTP proxy tunnel to www.stubhub.com:80
> CONNECT www.stubhub.com:80 HTTP/1.1

端口 80 用于纯 HTTP。然而,客户端将尝试 https(基于 TLS 的 HTTP),因为这是 URL 所说的。因此,客户端将尝试通过发送 ClientHello 来启动 TLS 握手。由于服务器需要一个普通的 HTTP 请求,但却得到了一个 TLS ClientHello,它会用 HTTP 错误响应进行回复。然后客户端将尝试将此响应解析为预期的 TLS 响应并失败:

error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

How to fix this?

不要将 CURLOPT_PORT 设置为 80。只是不要设置 CURLOPT_PORT 以便它从 URL 中获取。来自documentation :

This option sets number to be the remote port number to connect to, instead of the one specified in the URL or the default port for the used protocol. Usually, you just let the URL decide which port to use but this allows the application to override that.

关于php - curl 错误 :140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52918661/

62 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com