• Uncategorized

About php : Error-executing-curl-from-php

Question Detail

The following code runs perfectly using POSTMAN. While I try to use the code generated by postman for PHP, it gives me errors.

Original Code:

curl -X POST \
  'http://111.93.2.38:8080/gsp/gsp/authenticate?grant_type=token' \
  -H 'cache-control: no-cache' \
  -H 'gspappid: 64AB7894D61644F3B5CA18B4738C700D' \
  -H 'gspappsecret: 70988876GEEEEG4504GB400G92B801E23686' \

PHP Code:

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_PORT => "8080",
  CURLOPT_URL => "http://111.93.2.38:8080/gsp/gsp/authenticate?grant_type=token",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "gspappid: 64AB7894D61644F3B5CA18B4738C700D",
    "gspappsecret: 70988876GEEEEG4504GB400G92B801E23686",
    "postman-token: ff8278bb-b888-9fd3-6a55-780dafd58aa5"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

Please help me.

Question Answer

What kind of error are you facing , can you please share so we can help you?
If there is timeout error , you can try changing value of CURLOPT_TIMEOUT => 30

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.