Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

saber对url中的","的处理与其他http客户端有不一样的地方 #153

Open
Ben-Huang opened this issue Nov 9, 2023 · 0 comments

Comments

@Ben-Huang
Copy link

saber会对url中的","转码成"%2C",而其他http客户端,如SwooleHttpClient,GuzzleHttp,file_get_contents等不会对url中的","进行处理.

测试代码:

<?php
use Swlib\SaberGM;
use function Swoole\Coroutine\Http\get;


require __DIR__ . '/vendor/autoload.php';

date_default_timezone_set( 'Asia/Shanghai' );

swoole_error_log(SWOOLE_LOG_INFO, "php version:" . PHP_VERSION);
swoole_error_log(SWOOLE_LOG_INFO, "swoole version:" . swoole_version());

$composerLock = json_decode(file_get_contents('composer.lock'), true);
$packages = $composerLock['packages'];

foreach ($packages as $package) {
    swoole_error_log(SWOOLE_LOG_INFO, "package: " . $package['name'] . " | version: " . $package['version']);
}

go(function () {
    $url = 'http://eu.httpbin.org/get?max_results=50&tweet.fields=lang,created_at,attachments,author_id';
    swoole_error_log(SWOOLE_LOG_INFO, "SaberGM test start" );
    $options= [
        'proxy' => 'socks5://127.0.0.1:10808',
        'socks5_host' => '127.0.0.1',
        'socks5_port' => 10808,
    ];
    $res  = SaberGM::get($url,$options)->body;

    swoole_error_log(SWOOLE_LOG_INFO, "server return url: " . json_decode($res, true)['url']);
    swoole_error_log(SWOOLE_LOG_INFO, "SaberGM test end" );

    swoole_error_log(SWOOLE_LOG_INFO, "SwooleHttpClient test start" );
    $res = get($url,$options)->getBody();
    swoole_error_log(SWOOLE_LOG_INFO, "server return url: " . json_decode($res, true)['url']);
    swoole_error_log(SWOOLE_LOG_INFO, "SwooleHttpClient test end" );


    swoole_error_log(SWOOLE_LOG_INFO, "GuzzleHttp test start" );
    $client = new GuzzleHttp\Client();
    $res = $client->request('GET', $url , $options)->getBody();
    swoole_error_log(SWOOLE_LOG_INFO, "server return url: " . json_decode($res, true)['url']);
    swoole_error_log(SWOOLE_LOG_INFO, "GuzzleHttp test end" );

    swoole_error_log(SWOOLE_LOG_INFO, "file_get_contents test start" );
    $res = file_get_contents($url);
    swoole_error_log(SWOOLE_LOG_INFO, "server return url: " . json_decode($res, true)['url']);
    swoole_error_log(SWOOLE_LOG_INFO, "file_get_contents test end" );

});
Swoole\Event::wait();

输出结果:

[2023-11-09 17:26:52 @819.0]    INFO    php version:8.1.12
[2023-11-09 17:26:52 @819.0]    INFO    swoole version:5.0.3
[2023-11-09 17:26:52 @819.0]    INFO    package: guzzlehttp/guzzle | version: 7.8.0
[2023-11-09 17:26:52 @819.0]    INFO    package: guzzlehttp/promises | version: 2.0.1
[2023-11-09 17:26:52 @819.0]    INFO    package: guzzlehttp/psr7 | version: 2.6.1
[2023-11-09 17:26:52 @819.0]    INFO    package: psr/http-client | version: 1.0.3
[2023-11-09 17:26:52 @819.0]    INFO    package: psr/http-factory | version: 1.0.2
[2023-11-09 17:26:52 @819.0]    INFO    package: psr/http-message | version: 1.1
[2023-11-09 17:26:52 @819.0]    INFO    package: ralouphie/getallheaders | version: 3.0.3
[2023-11-09 17:26:52 @819.0]    INFO    package: swlib/http | version: v1.0.8
[2023-11-09 17:26:52 @819.0]    INFO    package: swlib/saber | version: v1.0.18
[2023-11-09 17:26:52 @819.0]    INFO    package: swlib/util | version: v1.0.3
[2023-11-09 17:26:52 @819.0]    INFO    package: symfony/deprecation-contracts | version: v3.3.0
[2023-11-09 17:26:52 @819.0]    INFO    SaberGM test start
[2023-11-09 17:26:53 @819.0]    INFO    server return url: http://eu.httpbin.org/get?max_results=50&tweet_fields=lang%2Ccreated_at%2Cattachments%2Cauthor_id
[2023-11-09 17:26:53 @819.0]    INFO    SaberGM test end
[2023-11-09 17:26:53 @819.0]    INFO    SwooleHttpClient test start
[2023-11-09 17:26:54 @819.0]    INFO    server return url: http://eu.httpbin.org/get?max_results=50&tweet.fields=lang,created_at,attachments,author_id
[2023-11-09 17:26:54 @819.0]    INFO    SwooleHttpClient test end
[2023-11-09 17:26:54 @819.0]    INFO    GuzzleHttp test start
[2023-11-09 17:26:55 @819.0]    INFO    server return url: http://eu.httpbin.org/get?max_results=50&tweet.fields=lang,created_at,attachments,author_id
[2023-11-09 17:26:55 @819.0]    INFO    GuzzleHttp test end
[2023-11-09 17:26:55 @819.0]    INFO    file_get_contents test start
[2023-11-09 17:26:55 @819.0]    INFO    server return url: http://eu.httpbin.org/get?max_results=50&tweet.fields=lang,created_at,attachments,author_id
[2023-11-09 17:26:55 @819.0]    INFO    file_get_contents test end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant