Guzzle Curl Failing With Connection Refused - php

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!

Related

Laravel Guzzle error when post to url in job queue

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

PHP Soap Client cannot load https wsdl link

I have been trying to load a particular https wsdl via php soapclient.
The error that I am getting is:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://xxxx.com?wsdl' : failed to load external entity "https://xxxx.com?wsdl"
Moreover I also try to "Curl https://xxxx.com?wsdl" as well. The error that I am getting is:
curl: (35) error:141A318A:SSL routines:tls_process_ske_dhe:dh key too
small
I am able to view the particular wsdl via browser. Curl with http instead of https returns the correct response.
The weird thing is that, my colleague has ubuntu 18.04 installed on his machine and he does not have any problems. For your information, I have debian 10 installed and we both have the same IP address.
I really don't understand where the issue can be.
You should try disable certificate validation when construct SoapClient instance
$context = stream_context_create([
'ssl' => [
// set some SSL/TLS specific options
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]);
$client = new SoapClient($url, [
... ( other params )
'stream_context' => $context
]);
If you use curl from command line you can use the --insecure/-k flag.

SOAPClient Error: Could not connect to host on PHP 7.0 and Laravel

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.

Laravel Guzzle Could Not Resolve Host

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.

GuzzleHTTP kills php-fpm when trying to POST to SSL secured URL

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
{
// ...
}

Categories