2
votes

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 ?

1
How is your nginx https configuration? Have you checked the url with another client like Postman etc? Is it throwing 502 with other clients or is this the case only with guzzle?Ugur
@ugur I got 502 Response from my server that is running Guzzle, I browse to method that contains Guzzle code over browser, like my-site.com/guzzle/index, which contains method that I posted above.user991
just to clarify, when you make a post request with another client(different then your guzzle client) to https://payment.my-url.com/gw/testing you succeed. I'm trying to figure out if remote server responding https requests correctly.Ugur
@ugur Yes, I got everything ok when trying with other clients. Problem is only when sending request with guzzleuser991
I tested your code with one of my https endpoints and it's working as expected. Did you try to remove the Accept and User-Agent headers? Do you have access to remote server's error logs? There may be useful information about what you are doing wrong.Ugur

1 Answers

1
votes

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