Jump to content

passing POST value to CURLOPT_POSTFIELDS


Go to solution Solved by Barand,

Recommended Posts

I am running a php curl postman API in a procedural php script

curl_setopt_array($curl, array(
  CURLOPT_URL => API_SERVER.'/url/SaveUser',
  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 =>'{"user":"user01","name":"John Doe","card":"0","password":"","privilege":"14","deviceSerial":"xxxxxxxxxxx"}',
  CURLOPT_HTTPHEADER => array(
    API_TOKEN ,
    'Content-Type: text/plain'
  ),
));

The post above works normally, but I need to POST a value into the  CURLOPT_POSTFIELDS.

I tried using variable name, but the value that is sent is the actual variable name, and not the value that the variable holds.

 
$user_id = $_POST[user_id];

CURLOPT_POSTFIELDS =>'{"user":"$user_id","name":"John Doe","card":"0","password":"","privilege":"14","deviceSerial":"xxxxxxxxxxx"}',

 

Can anyone please advise?

Many Thanks

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.