1

I've defined a proxy in my settings.php:

$settings['http_client_config']['proxy']['http'] = 'http://ip:port';
$settings['http_client_config']['proxy']['https'] = 'http://ip:port';
$settings['http_client_config']['proxy']['no'] = ['127.0.0.1', 'localhost'];

In real I've replaced ip and port with nummeric values.

In a custom module I've defined:

$client = \Drupal::httpClient();
//$request = $client->get($this->source_url.'service=wms&request=getcapabilities');

These works, when Im not behind a proxy. How, can I add the proxy settings to this request?

$set =\Drupal\Core\Site\Settings::get('http_client_config');
$proxy = $set['proxy'];
//Get GetCapabilies.
$client = \Drupal::httpClient();
$request = $client->get($this->source_url.'service=wms&request=getcapabilities');

I don't find any way to add the proxy settings.

1
0

You can pass all http client config to the "client factory". You can also include your own custom settings.

$settings = \Drupal::service('settings');
$clientConfig = $settings->get('http_client_config') ?? [];
$client = \Drupal::service('http_client_factory')
                   ->fromOptions($clientConfig);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.