https url not working
Closed this issue · 27 comments
http tcp url working but https ssl url not working in xampp. May be have to add cer/pem certificate in your code. How to generate and add certificate in your code?
If you have not time to reply/contribute it then plz delete it from github...tnx
In order to support tcp connection reusing and socks5 proxy, It is difficult to add support for custom SSL context options.
Now you can try to use v1.9
, and specify context options (such as SSL local_cafile ...), example code:
$request = new Request('https://www.your.host/request/uri');
$request->setMethod('POST');
$request->setHeader('user-agent', 'test robot');
// specify context options of connect, such as SSL options
$request->contextOptions = [
'ssl' => ['verify_peer_name' => false, 'local_cert' => '/path/to/file.pem'],
];
more informations about context, see: https://www.php.net/manual/en/context.php
local cert not working 😭
Also plz add http and https auth proxy function.
Example:
function connect_to_http_proxy($host, $port, $destination, $creds=null) {
$context = stream_context_create(
['ssl'=> ['verify_peer'=> false, 'verify_peer_name'=> false]]
);
$soc = stream_socket_client(
"tcp://$host:$port", $errno, $errstr, 20,
STREAM_CLIENT_CONNECT, $context
);
if ($errno == 0) {
$auth = $creds ? "Proxy-Authorization: Basic ".base64_encode($creds)."\r\n": "";
$connect = "CONNECT $destination HTTP/1.1\r\n$auth\r\n";
fwrite($soc, $connect);
$rsp = fread($soc, 1024);
if (preg_match('/^HTTP/\d.\d 200/', $rsp) == 1) {
return $soc;
}
echo "Request denied, $rsp\n";
return false;
}
echo "Connection failed, $errno, $errstr\n";
return false;
}
$host = "proxy IP";
$port = "proxy port";
$destination = "chat.freenode.net:6697";
$credentials = "user:pass";
$soc = connect_to_http_proxy($host, $port, $destination, $credentials);
if ($soc) {
stream_socket_enable_crypto($soc, true, STREAM_CRYPTO_METHOD_ANY_CLIENT);
fwrite($soc,"USER test\nNICK test\n");
echo fread($soc, 1024);
fclose($soc);
}
Try to specify proxy via stream context options, see https://www.php.net/manual/en/context.http.php
…
在 2021年10月3日,19:11,emma-eva @.***> 写道: local cert not working 😭 Also plz add http and https auth proxy function. Example: function connect_to_http_proxy($host, $port, $destination, $creds=null) { $context = stream_context_create( ['ssl'=> ['verify_peer'=> false, 'verify_peer_name'=> false]] ); $soc = stream_socket_client( "tcp://$host:$port", $errno, $errstr, 20, STREAM_CLIENT_CONNECT, $context ); if ($errno == 0) { $auth = $creds ? "Proxy-Authorization: Basic ".base64_encode($creds)."\r\n": ""; $connect = "CONNECT $destination HTTP/1.1\r\n$auth\r\n"; fwrite($soc, $connect); $rsp = fread($soc, 1024); if (preg_match('/^HTTP/\d.\d 200/', $rsp) == 1) { return $soc; } echo "Request denied, $rsp\n"; return false; } echo "Connection failed, $errno, $errstr\n"; return false; } $host = "proxy IP"; $port = "proxy port"; $destination = "chat.freenode.net:6697"; $credentials = "user:pass"; $soc = connect_to_http_proxy($host, $port, $destination, $credentials); if ($soc) { stream_socket_enable_crypto($soc, true, STREAM_CRYPTO_METHOD_ANY_CLIENT); fwrite($soc,"USER test\nNICK test\n"); echo fread($soc, 1024); fclose($soc); } — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.
It's not working.... I have to use proxy username and password. Plz show me example how to i send auth request in your code. Thanks
I tried like this:
$request->contextOptions = [ 'http' => ['proxy' => 'tcp://'.$PROXY_RACK_DNS.':'.$PROXY_RACK_PORT, 'request_fulluri' => true, 'header' => 'Proxy-Authorization: Basic '.$basicAuth] ];
But not working
Yes, this way does not work. And http proxy supports may need to be re-implemented, sorry.
I tried like this:
$request->contextOptions = [ 'http' => ['proxy' => 'tcp://'.$PROXY_RACK_DNS.':'.$PROXY_RACK_PORT, 'request_fulluri' => true, 'header' => 'Proxy-Authorization: Basic '.$basicAuth] ];
But not working
I tried also using this code, It's working.
$a = stream_context_create(['http' => ['proxy' => "tcp://$PROXY_RACK_DNS:$PROXY_RACK_PORT", 'request_fulluri' => true, 'header' => "Proxy-Authorization: Basic ".$auth]]);
$url = "http://ip-api.com/json";
echo file_get_contents($url, null, $a);
Plz solve it in your code. I want to use your code.
Any solution? plz check above comment.
They doing it also but why can't you do it?
Check this:
https://github.com/shtse8/easyrequest
https://github.com/shtse8/easyrequest/blob/master/src/Handler/Socket.php
https://github.com/weird/HttpClient/blob/master/HttpClient.php
Just follow this codes, i hope so you can make http proxy support Proxy-Authorization: Basic
1.) https://github.com/shtse8/easyrequest/blob/master/src/Handler/Socket.php
2.) https://github.com/weird/HttpClient/blob/master/HttpClient.php
https request working in hosting server... Its enough. Just add http auth.. Proxy support. Thanks
As i see that you updated sometimes ago but not seeing http proxy auth support code
Ok, waiting... But add it as quickly as possible. Bcz my work stopped for that... I don’t like curl and any others library... I like your httpclient.
Ok, waiting... But add it as quickly as possible. Bcz my work stopped for that... I don’t like curl and any others library... I like your httpclient.
Why use this library so persistently, you can try to use branch proxy-wip
, but there is still a small bug with some SSL sites, it seems PHP-bug with non-blocking stream.
Just waste your last time to add http proxy support.... If you got time in future then upgrade more... Thanks
Use v1.11 plz... It supports socks5/socks4/http proxy now, and works well with HTTPS.
V1.11 will support http proxy authentication username and password?
Getting http proxy Authentication error:
[status] => 400
[statusText] => Bad Request
[error] => Proxy communication error: 407 Proxy Authentication Required
[body] =>
[timeCost] => 0.31800293922424
[url] => http://ip-api.com/json
[numRedirected] => 0
[_headers:protected] => Array
(
)
[_cookies:protected] => Array
(
)
Trying like this:
$http = new Client();
Connection::useProxy('http://username:password@proxy.packetstream.io:31112');
Client::debug('open');
$csr = $http->get('http://ip-api.com/json');
echo '<pre>'; print_r($csr);
Sorry, the authentication code is missing, fixed now.
Getting http proxy Authentication error:
It's working, great job bro. Can you help me to reverse engineering an android app? I need app private api... I am ready to pay you. Thanks