Good Postman request don’t work on my php website

  Kiến thức lập trình

Good morning. On Postman, I created a query which returns me a result but the generated code (PHP-CURL) which seems correct to me does not return “false”
Method POST
Postman Config:

Params => nothing
Authorization => default (inherit auth …)
Headers => content-type: application/json, data-type: jsonp
Body => {
“Username”: “user-name”,
“Password”: “pass-word”
}

Postman return:

{
    "access_token": "xxxxxxx",
    "token_type": "xxx",
    "expires_in": 10799,
    "userName": "user-name",
    "issued": "2024-04-26T08:58:24Z",
    "expires": "2024-04-26T11:58:24Z",
    "error": "",
    "error_description": ""
}

Postman code generate:

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://XXX/api',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "Username": "user-name",
    "Password": "pass-word"
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'dataType: jsonp'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

But $response = false

For information, I work on a local server

Thanks for your help

LEAVE A COMMENT