When used http client cakephp 3 Cannot Get Response

i’ll tried to request with http client, to url : https://equran.id/api/surat/1 , that my code

	public $urlquran = "https://equran.id/api/surat";
	
	public function getayat($randomsurat =null){
		$http = new Client();
		$response = $http->get("$this->urlquran/$randomsurat");
        if($response->isOk()){
			$data = $response->getJson();
			return debug($data);
		}else{
			return "Error meminta Ayat";
		}
		
	}

But i am got the 502 Bad Gate way, What the Problems ?

Your screenshot of the 502 error is calling https://siumpeg.ummi.ac.id
but your code above mentions https://equran.id/api/surat which is not the same domain.

Are you certain that you are calling the right domain?

1 Like

oh ya, sorry, my right domain it https://siumpeg.ummi.ac.id, i tried to request api to my component with http angularjs and my component request to equran with http too like code on top, but the response is 502 bad gate way, my server using nginx, i tried this code on my localhost its’ work, but i tried live on angularjs, and live on component controller not work
it my code angularjs live

$scope.getayat = function(){
console.log(‘OK’);
var req = {
method: ‘GET’,
url: “https://equran.id/api/surat/1”,
headers: {
‘X-CSRF-Token’: <?= json_encode($this->request->getParam('_csrfToken')); ?>,
‘Access-Control-Allow-Origin’:‘*’,
‘Content-Type’: ‘application/json; charset=utf-8’,
“X-Requested-With”: “XMLHttpRequest”

                },
                data:null
               };
        $http(req).then(function(response){
             console.log(response);
        });

}

$scope.getayat();

and its code my component

public $urlquran = “https://equran.id/api/surat”;

public function getayat($randomsurat =null){
$http = new Client();
$response = $http->get(“$this->urlquran/$randomsurat”);
if($response->isOk()){
$data = $response->getJson();
return debug($data);
}else{
return “Error meminta Ayat”;
}

}