我正在尝试将AMPHP HTTP-Client与代理一起使用,但我无法使其工作。
我使用的是他们的GitHub中的示例。(https://github.com/amphp/http-tunnel/blob/master/examples/http-client-via-proxy.php)
我必须下载10个URL,并为每个URL使用不同的代理。当前的问题是,它返回这种类型的错误:
TLS negotiation failed: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:1408F10B:SSL routines:ssl3_get_record:wrong version number我们的代理服务器使用证书(.crx)进行操作。我不需要检查SSL是否有效,我只想跳过验证,所以我认为这些行可以做我需要的事情(跳过验证),但它们不...?
$clientTlsContext = new ClientTlsContext('');
$clientTlsContext->withoutPeerVerification();
$clientTlsContext->withSecurityLevel(0);这适用于curl:
curl_setopt($curlResource, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curlResource, CURLOPT_SSL_VERIFYHOST, 0);这是我的代码:
class AMPHPDownloaderTest
{
/**
* @param ConfigWithCallback[] $configsWithCallback
*/
public static function downSerps($configsWithCallback): void
{
Loop::run(static function () use ($configsWithCallback) {
try {
$clientTlsContext = new ClientTlsContext('');
$clientTlsContext->withoutPeerVerification();
$clientTlsContext->withSecurityLevel(0);
$connector = new Https1TunnelConnector(new SocketAddress('proxyi2.infatica.io', 44123), $clientTlsContext);
$client = (new HttpClientBuilder)
->usingPool(new UnlimitedConnectionPool(new DefaultConnectionFactory($connector)))
->build();
$request = new Request('http://amphp.org/');
/** @var Response $response */
$response = yield $client->request($request);
$request = $response->getRequest();
\printf(
"%s %s HTTP/%s\r\n",
$request->getMethod(),
$request->getUri(),
\implode('+', $request->getProtocolVersions())
);
print Rfc7230::formatHeaders($request->getHeaders()) . "\r\n\r\n";
\printf(
"HTTP/%s %d %s\r\n",
$response->getProtocolVersion(),
$response->getStatus(),
$response->getReason()
);
print Rfc7230::formatHeaders($response->getHeaders()) . "\r\n\r\n";
$body = yield $response->getBody()->buffer();
$bodyLength = \strlen($body);
if ($bodyLength < 250) {
print $body . "\r\n";
} else {
print \substr($body, 0, 250) . "\r\n\r\n";
print($bodyLength - 250) . " more bytes\r\n";
}
} catch (HttpException $error) {
echo $error;
}
});
}
}当与Http1TunnelConnector而不是Https1TunnelConnector一起使用时,它会抛出以下错误:
Amp\Socket\TlsException: TLS negotiation failed: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed发布于 2020-07-05 15:36:00
您基本上是在做正确的事情,但是ClientTlsContext是不可变的,并且总是返回一个新的实例,该实例在您的代码示例中被丢弃。
$clientTlsContext = (new ClientTlsContext(''))
->withoutPeerVerification()
->withSecurityLevel(0);https://stackoverflow.com/questions/62632675
复制相似问题