In my job,I am using guzzle to call api abc.com/test
Sometime, when a lot of job in application. Job become fail
cURL error 6: Could not resolve host: router; Unknown error (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
All endpoint which use guzzle changed to "router".
$config = [
'verify' => false,
'timeout' => 30,
'headers' => ['Content-Type' => 'application/json'],
];
$this->httpClient = new Client($config);
$response = $this->httpClient->request("POST",'abc.com/updateProduct', $data)
we just ran into the same issue and for us downgrading our NewRelic PHP Agent solved the issue, more info: https://github.com/newrelic/newrelic-php-agent/issues/255
Related
For a customer we're making a (secured) Soap connection with a Dutch asbestos governmental API in PHP (Laravel in our case) but we are struggling with setting it up.
We've received a guide on how to create the required SSL certificate files, mailed them to the company that provides the API, tested the .wsdl file with SSL(with the .pfx file) in SoapUI and everything works perfectly.
But when we use it in PHP's SoapClient, an Exception is thrown mentioning:
"Could not connect to host"
Here's our code:
$wsdl = resource_path("wsdl/testing/portal_1_1.wsdl");
/**
* #see https://www.php.net/manual/en/soapclient.construct.php
*/
$options = [
'location' => 'https://acceptatie.tws-esb.rws.nl/lavs-koppelvlak-bacc',
'local_cert' => resource_path("certs" . DIRECTORY_SEPARATOR . "vdm-lavs.pem"),
'passphrase' => 'Pr0v!de',
'cache_wsdl' => "WSDL_CACHE_NONE",
'trace' => true,
'exceptions' => true,
'soap_version' => SOAP_1_1,
'stream_context' => stream_context_create([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
])
];
$soapClient = new \SoapClient($wsdl, $options);
$result = $soapClient->__soapCall('statusOpvraging', []);
What I've checked so far is :
Adding allow_self_signed to the ssl configuration
Since the SoapUI uses the .pfx certificate and the local_cert in SoapClient in PHP does not work with .pfx but .pem, we tried both
We tried it in Postman as a regular HTTP call and it works fine
We've tried in an old PHP 5.6 and Laravel 5.3.0 and a new fresh PHP 8.0 with Laravel 8.68.1 configuration, both result in the same error.
Does anybody have any suggestion?
I am having issues connecting to a WSDL via SOAPClient on my Laravel application in a server with PHP 7.0. I have tested the following code on my local server using PHP 5.6 and it works. Both are running Linux; my local server is running Kubuntu and the other server is running CentOS 7.
var $client;
function __construct(){
ini_set('soap.wsdl_cache_enabled',WSDL_CACHE_NONE);
ini_set('soap.wsdl_cache_ttl', 0);
$this->client = new SoapClient(env('WSDL_SOLMAN02_TEST'),
['login'=>env('SOLMAN_US_TEST'),
'password'=>env('SOLMAN_PSSWD_TEST'),
'cache_wsdl' => WSDL_CACHE_NONE,
'soap_version' => SOAP_1_1,
'ssl_method' => 'SOAP_SSL_METHOD_SSLv3',
'trace' => true,
'exception' => false,
'stream_context'=> stream_context_create(array(
'ssl'=> array(
'verify_peer'=>false,
'verify_peer_name'=>false
)
))
]
);
}
public function updateTicket(Ticket $ticket){
$incident = $this->createTicketObject($ticket);
$params = get_object_vars($incident);
return $this->client->wsdlFunc($params);
}
The funny thing is that when I print dd($this->client->__getFunctions()); the WSDL responds with an array of all the functions that you can call, but when I actually call upon any function, the error is displayed.
I have tried just about everything, from changing every parameter in the connection to changing the php.ini, but nothing has worked. I have downgraded the server to PHP 5.6 and it still doesn't work.
I have also tested WSDL on SOAPUI and it works.
The only difference I find between both environments is that the server with PHP 7.0 has https.
My code was fine, I just had to add the WSDL ip address to /etc/hosts.
I faced the same problem when I upgraded from php v7.2 to v7.3 (docker):
SOAPClient Error: Could not connect to host
I tried the solution proposed by #suecamol but it did not work. Looks like php v7.3 changed something with the ssl security.
The solution, that one of my co-worker found, was to add a proper ssl ciphers encryption:
$arrContextOptions= [
'ssl' => [
'ciphers' => 'AES256-SHA',
]
];
$options = [
...
'stream_context' => stream_context_create($arrContextOptions),
];
$client = new SoapClient('some wsdl url', $options);
Hopefully this can help someone facing this issue.
I have a Laravel application which is hosted locally on a local IP.
It will always be hosted internally on the IP.
I'm trying to connect my application to Interlinks API, on sending a $client->post() I get the following error:
ConnectException in CurlFactory.php line 186: cURL error 6: Could not
resolve host: headers (see
http://curl.haxx.se/libcurl/c/libcurl-errors.html)
Below is the code in my controller.
$client = new \GuzzleHttp\Client();
$client->setDefaultOption('headers', array('Accept' => 'application/json', 'Content-Type' => 'application/json', 'GEOSESSION' => 'MTAuMjYuMy43asdasdasdasdTky'));
$body = json_encode($job);
$res = $client->post('https://api.interlinkexpress.com/shipping/shipment',['body' => $body]);
dd($res);
Does anyone have any ideas why I get the could not resolve host? I'm hoping it's nothing to do with being local.
Thanks
Try to use the latest Guzzle (6.2 at the moment).
It seems that you are using older version, because setDefaultOption is not available in 6.x.
I'm using Guzzle 6.0.2 ( Also tried with 5.3.0 ) in Laravel environment.
For testing purposes I created Controller with index method to test Guzzle POST request to other web server.
My method:
<?php
public function index()
{
$uri = 'https://payment.my-url.com/gw/testing';
// $uri = 'http://pay.my-url.com/gw/testing';
$client = new \GuzzleHttp\Client();
$resource = $client->post($uri, [
'json' => ['foo' => 'bar'],
'headers' => [
'Accept' => '*/*; q=0.5, application/xml',
'Content-Type' => 'application/json; charset=utf-8',
'User-Agent' => 'Client/1.0',
],
]);
$statusCode = $resource->getStatusCode();
}
When I try to access URL with this method, i receive 502 Bad Gateway from my server, but it only occours if I'm trying to send to HTTPS $uri. If I send to HTTP ( non secure ) uri then my request goes to foreign web server and there I can dump POST data array.
I have nginx 1.8.0 and PHP 5.6.9 on OSX environment.
I also tried to add extra configuration to guzzle client but this does not make any difference:
'curl' => [
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
],
'verify' => false,
Why my web server gives me 502 bad Gateway when I try to send POST to HTTPS uri with GuzzleHTTP component ?
Problem was because of using Bugsnag error handler on Laravel
If changing Laravel handler.php file to use default laravel handler, then error is thrown, if Busnag error handler is used then nginx dies with 502 error, and no error is reported to Bugsnag or Web logs.
Example of file:
<?php namespace Payrex\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
// use Bugsnag\BugsnagLaravel\BugsnagExceptionHandler as ExceptionHandler;
class Handler extends ExceptionHandler
{
// ...
}
I am trying to figure out why my Guzzle request is throwing a number 7 error when cURLing.
Here is my guzzle code:
use GuzzleHttp\Client;
$client = new Client([
'base_url' => ['http://mysite.local:8000/api/v1.0.0', []],
'defaults' => [
'proxy' => 'http://mysite.local:8000'
]
]);
$request = $client->createRequest('GET', 'simplecontroller/index', [
'query' => ['foo' => 'bar']
]);
$response = $client->send($request);
var_dump($response); // <-- is not happening becauase:
It is failing on CurlAdapter::send(). The cURL request is throwing an error, and thus being handled by the handleError method. Here is the error message:
string 'Failed to connect to mysite.local port 8000: Connection refused'
Any idea of what might need to change? I am working on a project that talks to an API, and that api code also happens to be in development as well on my local machine. I am also using Vagrant Homestead if that helps. As far as I can tell, it should be possible to cURL to a local url for testing purposes. If it is not, please let me know.
Thanks!