2

Guzzle ライブラリを使用してクライアント サーバーで Web サービスを呼び出そうとしていますが、サーバーにプロキシがあるため、コードで 404 エラーが発生します。

クライアントサーバーにsshして試してみると

wget http://www.mywebsite.com/mywebservice

エラーが発生する

Resolving proxy.theirdomainname.com (proxy.theirdomainname.com)... xx.xx.xx.xx
Connecting to proxy.theirdomainname.com (proxy.theirdomainname.com)|xx.xx.xx.xx|:80...
failed: Connection timed out.

しかし、私が使用する場合

wget --no-proxy http://www.mywebsite.com/mywebservice

結果が出ます

Resolving www.mywebsite.com (www.mywebsite.com)... xx.xx.xx.xx
Connecting to www.mywebsite.com (www.mywebsite.com)|xx.xx.xx.xx|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

Guzzle のドキュメントでプロキシを設定するオプションを確認できます - http://guzzle.readthedocs.org/en/latest/http-client/client.html#proxy

しかし、プロキシの使用を完全に無効にするにはどうすればよいでしょうか? それともサーバー設定でしょうか?

編集:

$request = $client->get($this->url(), array('proxy' => ''))
                  ->setHeader('Accept', 'text/xml');

$response = $request->send();
var_dump($response);

結果 :

Fatal error: Uncaught exception 'Guzzle\Http\Exception\ClientErrorResponseException'
with message 'Client error response [status code] 404 [reason phrase] Not Found [url] http://mywebsite.com'
in /vendor/guzzle/guzzle/src/Guzzle/Http/Exception/BadResponseException.php:44 
Stack trace: #0 /guzzle/guzzle/src/Guzzle/Http/Message/Request.php(145): Guzzle\Http\Exception\BadResponseException::factory(Object(Guzzle\Http\Message\Request), Object(Guzzle\Http\Message\Response)) 
#1 [internal function]: Guzzle\Http\Message\Request::onRequestError(Object(Guzzle\Common\Event))
#2 /vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(164): call_user_func(Array, Object(Guzzle\Common\Event))
#3 /vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(53): Symfony in /vendor/guzzle/guzzle/src/Guzzle/Http/Exception/BadResponseException.php on line 44
4

2 に答える 2

4

Guzzlehttp6 を使用している場合:

  • 特定のタイプのプロトコルに別のプロキシを指定する場合:

     $client->request('GET', 'your_url_here', [
    'proxy' => [
    'http'  => 'tcp://localhost:8125', // Use this proxy with "http"
    'https' => 'tcp://localhost:9124', // Use this proxy with "https",
    'no' => ['.mit.edu', 'foo.com']    // Don't use a proxy with these
       ]
    ]);
    
  • すべてのクエリに対してプロキシを無効にする場合:

    $client->request('GET','your_url_here',['proxy'=>'']);
    

    公式ドキュメントへのリンク。

于 2015-12-16T14:35:29.810 に答える
1

これGuzzle\Clientは、システム環境変数を見て自動的にプロキシを設定するためです。Linux と Windows のどちらを使用しているかは問題ではありません。

  280:         // Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set
  281:         if ($proxy = getenv('HTTP_PROXY')) {
  282:             $settings['proxy']['http'] = $proxy;
  283          }
  284  
  285:         if ($proxy = getenv('HTTPS_PROXY')) {
  286:             $settings['proxy']['https'] = $proxy;
  287          }

したがって、以前に次のようなものを使用してプロキシを設定した場合

set HTTP_PROXY=http://your.proxy.local:8080
set HTTPS_PROXY=http://your.proxy.local:8080

次に、このプロキシ設定が選択されます。

Marcell Fülöp が言ったように、空のプロキシを強制する必要があります。

于 2014-12-16T17:19:30.310 に答える