V
V
Vladislav2021-06-30 12:57:48
PHP
Vladislav, 2021-06-30 12:57:48

Curl+Proxy not working on server?

I am using Yii2 httpclient

$client = new Client(['transport' => 'yii\httpclient\CurlTransport']);
        $response = $client->createRequest()
            ->setMethod('GET')
            ->setUrl($url)
            ->setHeaders([
                'Connection' => 'keep-alive',
                'sec-ch-ua' => '"Google Chrome";v="87", " Not;A Brand";v="99", "Chromium";v="87"',
                'Accept' => 'application/json, text/javascript, */*; q=0.01',
                'X-Requested-With' => 'XMLHttpRequest',
                'sec-ch-ua-mobile' => '?0',
                'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36',
                'Sec-Fetch-Site' => 'same-origin',
                'Sec-Fetch-Mode' => 'cors',
                'Sec-Fetch-Dest' => 'empty',
                'Accept-Language' => 'ru,en-US;q=0.9,en;q=0.8'
            ])
            ->setOptions([
                CURLOPT_PROXY => $this->proxy->getAddress(),
                CURLOPT_PROXYUSERPWD => $this->proxy->getLogin() . ":" . $this->proxy->getPassword(),
            ])
            ->send();


Here is the request code. Everything works on local: Openserver php 7.2
on phpfpm 7.2 server
but it doesn't work there and gives the following error:
File: vendor/yiisoft/yii2-httpclient/src/CurlTransport.php
Curl error: #56 - Received HTTP code 502 from proxy after CONNECT


What could be the problem ?
Mobile proxies from onlinesim.
The $this->proxy->getAddress(), $this->proxy->getLogin() and $this->proxy->getPassword() methods return valid data.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vitaly_74, 2021-07-01
@vitaly_74

https://success.outsystems.com/Support/Enterprise_...

HTTP Response Code 502 - Invalid Gateway Server indicates that the server, acting as a gateway or proxy, received an invalid response from an upstream server. In typical production scenarios, there is a reverse proxy or load balancers in front of the server(s). Imagine that the client sent a request to the Server. However, the client cannot do this directly, so it connects to the proxy by establishing a client>proxy connection. The proxy then creates a connection proxy. HTTP Error 502 - Invalid Gateway occurs in the following cases:
The proxy server timed out before the request was completed.
If the proxy>server connection drops.
When the response from the server is invalid

I'm more inclined to either the server thinks for a long time. those. takes a long time to process a request. it can work on local only because the databases on local and prod are different and the information is different, and therefore looping can occur somewhere, or vice versa, long processing of information.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question