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
{
// ...
}
Related
I have a PHP (8.1.8) page hosted on Apache (2.4) on a Windows Server 2019 EC2 instance in AWS. It attempts to send an event to a Lambda Function. The page is called with HTTP, not HTTPS (don't ask - required for external calling system).
If I run the script in VSCode (for example) it works fine and I get a response from the Lambda Function (so I believe the EC2 instance has no problem talking to the Lambda Function). However if I request the page through a browser I get an error (XXXXX represents my Lambda Function name, obfuscated):
Fatal error: Uncaught exception 'Aws\Lambda\Exception\LambdaException' with message 'Error executing "Invoke" on "https://lambda.eu-west-1.amazonaws.com/2015-03-31/functions/XXXXX/invocations"; AWS HTTP error: Connection refused for URI https://lambda.eu-west-1.amazonaws.com/2015-03-31/functions/XXXXX/invocations' GuzzleHttp\Exception\ConnectException: Connection refused for URI https://lambda.eu-west-1.amazonaws.com/2015-03-31/functions/XXXXX/invocations in C:\Apache24\htdocs\vendor\guzzlehttp\guzzle\src\Handler\StreamHandler.php:328
The script is:
<?php
require 'vendor/autoload.php';
use Aws\Credentials\Credentials;
use Aws\Lambda\LambdaClient;
$data = 'TEST PAYLOAD';
$array_obj = array("xml" => $data);
$json_obj = json_encode($array_obj);
$credentials = new Aws\Credentials\Credentials('<<KEY>>', '<<SECRET>>');
$client = new Aws\Lambda\LambdaClient([
'version' => 'latest',
'region' => 'eu-west-1',
'credentials' => $credentials,
'debug' => false,
]);
$lambda_result = $client->invoke([
'FunctionName' => 'XXXXX',
'InvocationType' => 'RequestResponse',
'LogType' => 'None',
'Payload' => $json_obj,
]);
print_r(json_decode($lambda_result->get('Payload')->getContents(), true))
?>
I'm pretty sure I'm just missing some config that will allow the web page script to call the Lambda, but I'm drawing a blank searching around for an answer.
EDIT:
Edited to clarify that this is running on a Windows Server 2019 EC2 instance, and the page is called with HTTP, not HTTPS.
EDIT 2:
I get the same issue with SQS, so its not a Lambda thing specifically. Seems to be generally about accessing AWS resources through the SDK APIs? (Tags adjusted accordingly)
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
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.
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 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!