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

1 Answer 1

1

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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