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.
Related
I am trying to hit API endpoint from my Laravel 5.8.* project.
I am using Guzzle 6.0 with PHP version 7.1.3.
When I run my project in local machine, I get the API response successfully.
But after uploading the project to liver server, I could not get the API response.
I get the response "cURL error 7: Failed to connect to xx.xx.xx.xx port 3333: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)".
The code that I use is as follows.
$client = new GuzzleHttp\Client();
$res = $client->request('GET', 'http://xx.xx.xx.xx:3333/api/getrecords', [
'tbl' => ['user', 'activity']
]);
echo $res->getMessage();
The same code is working perfectly in local machine but not in live server.
My Server is Linux server.
Did you have any proxy configured in your server? If so, try to set a proxy in your guzzle request: Guzzle proxy docs
Basically, you have to set an array with the proxy.
$client->request('GET', '/', ['proxy' => 'tcp://localhost:8125']);
you are trying to make request using port 3333. This port 3333 needs to be open in your machine only then you will be able to make request from this port.
Getting this error message when trying to send any request using Guzzle php library. It is HTTP client based on curl. My example code to work:
$client = new GuzzleHttp\Client(['base_uri' => 'https://api.twitter.com/oauth/']);
$response = $client->request('POST', 'access_token');
error: cURL error 6: Could not resolve host: foo.ru (see
http://curl.haxx.se/libcurl/c/libcurl-errors.html)
I have tried any other url, update my /etc/resolv.conf error is the same.
Could you give me some ideas how to fix it ?
Ubuntu, PHP 7.2
I'm using GuzzHttp in my laravel project to post some data to an API. In my local enviroment I have to to create my client with the cacert.pem file verification like this:
$client = new \GuzzleHttp\Client(['verify' => 'C:\wamp64\bin\php\php7.2.14\cacert.pem']);
But I can't do so on my shared hosting. So, removing that verification:
$client = new \GuzzleHttp\Client();
Results on an internal server error:
[2019-06-11 15:17:10] local.ERROR: GuzzleHttp\Exception\ServerException: Server error: `POST https://pruebas2.mayoristaseguridad.es/tiendaseguridad/02-ConectorLaravelPrestashop/ConectorCategorias.php` resulted in a `500 Internal Server Error` response in /home/admin/web/iberoseguridad.eu/public_html/csv_products/vendor/guzzle/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Is there a way to fix this error?
Not sure if this will help, here it goes anyways
// Disable validation entirely (don't do this!).
$client->request('GET', '/', ['verify' => false]);
Guzzle verify api
This ended up being a remote server error, not mine. I just had to communicate that error with the server's maintainer and now it works just fine.
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!
I'm using Goutte to get a page on a web server using an SSL certificate. Whenever I try to get this page the the following exception is thrown:
Uncaught exception 'Guzzle\\Http\\Exception\\CurlException' with message
'[curl] 35: error:1407742E:SSL
routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
[url] https://somesite.com
I have been looking online for this type of error. It seems that this error happens when there is a handshake failure. The server seems to support TLSv1 and the client uses SSL23.
I'm not sure if this assessment is correct nor do I know how to correct it.
This is the code I'm currently using:
<?php
use Goutte\Client;
$client = new Client();
$guzzle = $client->getClient();
$guzzle->setConfig(
array(
'curl.CURLOPT_SSL_VERIFYHOST' => false,
'curl.CURLOPT_SSL_VERIFYPEER' => false,
)
);
$client->setClient($guzzle);
$crawler = $client->request('GET', 'https://somesite.com'); // IT FAILS HERE
UPDATE:
NOTE: I started getting a few weeks ago a similar error, so I thought I would update the question and answer as they are related.
I got a similar error:
[curl] 35: Unknown SSL protocol error in connection to website.com:443
I found the answer to this problem in the blogpost "Fixing SSL Handshake with PHP5 and Curl"
This error can happen in some operating systems but not in all making it a hard issue to replicate. I am currently using Ubuntu 12.04 in my development environment.
Thankfully this is something that can be addressed at the code level like this:
use Goutte\Client;
$client = new Client();
$guzzle = new GuzzleClient('https://somesite.com', array(
'curl.options' => array(
'CURLOPT_SSLVERSION' => 'CURL_SSLVERSION_TLSv1',
)
));
$client->setClient($guzzle);
$crawler = $client->request('GET', 'https://somesite.com');
UPDATE:
For the solution for the message
[curl] 35: Unknown SSL protocol error in connection to website.com:443
was a bit tricky to resolve as the message gives no indication of what is going on.
This GitHub issue pointed me in the right direction tho. There are multiple versions of the CURLOPT_SSLVERSION I can use (of course!), but these include v1.0, v1.1, and v1.2! See the curl_setopt for more information.
For this particular error I ended up using the following code:
$guzzle = new GuzzleClient('https://somesite.com', array(
'curl.options' => array(
'CURLOPT_SSLVERSION' => 'CURL_SSLVERSION_TLSv1_1',
)
));
The site I was trying to connect to would not accept any other option including CURL_SSLVERSION_TLSv1.