hightman / httpclient

A parallel HTTP client written in pure PHP
MIT License
107 stars 22 forks source link

https url not working #5

Closed emma-eva closed 3 years ago

emma-eva commented 3 years ago

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?

emma-eva commented 3 years ago

If you have not time to reply/contribute it then plz delete it from github...tnx

hightman commented 3 years ago

In order to support tcp connection reusing and socks5 proxy, It is difficult to add support for custom SSL context options.

hightman commented 3 years ago

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

emma-eva commented 3 years ago

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);
}
hightman commented 3 years ago

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.

emma-eva commented 3 years ago

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

emma-eva commented 3 years ago

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

hightman commented 3 years ago

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

emma-eva commented 3 years ago

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.

emma-eva commented 3 years ago

Any solution? plz check above comment.

hightman commented 3 years ago

I have tried to solve this problem, but it still cannot handle HTTPS requests. Because we make HTTP request manualy in TCP connection.

I suggest you use CURL extension in this case.

在 2021年10月5日,22:49,emma-eva @.***> 写道:

 Any solution? plz check above comment.

— 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.

emma-eva commented 3 years ago

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

tuberboy commented 3 years ago

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

hightman commented 3 years ago

In this way, HTTPS request still cannot be correct handled via PROXY_HTTP.

I have not enough time to make a full testing, you can implement this feature and create pull-request from github.

在 2021年10月7日,05:59,Tuber Boy @.***> 写道:

 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

— 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.

emma-eva commented 3 years ago

https request working in hosting server... Its enough. Just add http auth.. Proxy support. Thanks

emma-eva commented 3 years ago

As i see that you updated sometimes ago but not seeing http proxy auth support code

hightman commented 3 years ago

en, I will try when I have time, please wait a short while.

2021年10月7日 下午4:06,emma-eva @. @.>> 写道:

As i see that you updated sometimes ago but not seeing http proxy auth support code

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hightman/httpclient/issues/5#issuecomment-937553524, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGGKXMBOHOT5ZVCGPJZQSTUFVIIHANCNFSM5FCRSQAQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

emma-eva commented 3 years ago

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.

hightman commented 3 years ago

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.

emma-eva commented 3 years ago

Just waste your last time to add http proxy support.... If you got time in future then upgrade more... Thanks

hightman commented 3 years ago

Use v1.11 plz... It supports socks5/socks4/http proxy now, and works well with HTTPS.

emma-eva commented 3 years ago

V1.11 will support http proxy authentication username and password?

hightman commented 3 years ago

yes! It is released, you can fetch from master branch.

在 2021年10月7日,23:04,emma-eva @.***> 写道:

 V1.11 will support http proxy authentication username and password?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

emma-eva commented 3 years ago

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);
hightman commented 3 years ago

Sorry, the authentication code is missing, fixed now.

Getting http proxy Authentication error:

emma-eva commented 3 years ago

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

hightman commented 3 years ago

… sorry I cant do that.

在 2021年10月8日,18:00,emma-eva @.***> 写道:

 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

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.