skip to Main Content

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 GuzzleHttpClient();
$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.

2

Answers


  1. 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']);
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search