skip to Main Content

local works but in production it returns 403. Same PHP and Laravel version. Is there anything i can do?

$url = 'https://admin.appmax.com.br/api/v3/order/'.$order_id.'?access-token='.$token;            
$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => $url,
    CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true
]);

$response = curl_exec($curl);
curl_close($curl);`

I did all the tests, it doesn’t work only in production.

2

Answers


  1. You can try HTTP package.

    use IlluminateSupportFacadesHttp;
    
    Http::get('https://admin.appmax.com.br/api/v3/order/'.$order_id.'?access-token='.$token);
    
    Login or Signup to reply.
  2. You’re setting CURLOPT_POST to true, which indicates that you want to send a POST request, but you’re also setting CURLOPT_CUSTOMREQUEST to ‘GET’, which indicates that you want to send a GET request. You should remove the CURLOPT_POST option since you’re sending a GET request.

    Neither you’re passing the access token as a header. You’re passing it as a query parameter in the URL.

    Also, check the response for errors before processing it using curl_error.

    The following should work.

    $url = 'https://admin.appmax.com.br/api/v3/order/'.$order_id.'?access-token='.$token;            
    $curl = curl_init();
    
    curl_setopt_array($curl, [
        CURLOPT_URL => $url,
        CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
        CURLOPT_CUSTOMREQUEST => 'GET',
        CURLOPT_RETURNTRANSFER => true
    ]);
    
    $response = curl_exec($curl);
    
    if ($response === false) {
        echo 'cURL Error: ' . curl_error($curl);
        return;
    }
    
    $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    if ($httpCode != 200) {
        echo 'Error: ' . $httpCode;
        return;
    }
    
    curl_close($curl);
    // process $response
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search