0

I have collection on postman and it is working fine. But now, I am trying to convert this PHP cURL

curl --location --request POST 'https://test.url.com' \
--header 'Content-Type: application/x-www-form-urlencode' \
--header 'Authorization: Basic 1234567890' \
--data-urlencode 'abc_id=123456' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'scope=req-auth/all'

Here is my code:

$headers = [
                "Authorization: Basic 1234567890",
                "Content-Type: application/x-www-form-urlencode"
            ];
$data = [ 
            "abc_id" => '123456',
            "grant_type" => 'client_credentials',
            "scope" => 'req-auth/all',
        ];            
$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => http_build_query($data) 
));
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($curl);
$errno = curl_errno($curl);

curl_close($curl);
print_r($response);

I tried this code but it is not working on my end How to include 'data-urlencode' using php curl library

0 Answers0