PHP curl with post return an empty string

30
February 12, 2019, at 3:00 PM

l build a PHP curl to request an api to add a user's info into a remote server

$data contain the user's info, it is an array.

one param of $data named dept($data['dept']) maybe a long string, and this curl can work when dept is a short string, So l think it maybe data's length > 1024, So l added 'Expect:' in CURLOPT_HTTPHEADER but still didn't work. and after this l output the length of http_build_query($data). it didn't > 1024, it's length is 964(l test this always with the same param)

here is curl code:

$token = "xxxxx";
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 15); // set timeout with 15s
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect:', 'Content-Type: application/x-www-form-urlencoded', 'token: ' . $token));
// curl_setopt($curl, CURLOPT_HTTPHEADER, array());
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_URL, 'www.myapi.com/rest/user');
// var_dump(http_build_query($data));exit;
$res = curl_exec($curl);
var_dump($res);
$curl_error = curl_error($curl);
curl_close($curl);

var_dump($res); output this: string '' (length=0)

l tried to print curl_info($curl), it's http_code is 200

READ ALSO
I'm trying to create a Notification System without websockets & polling - Just simple JSON?

I'm trying to create a Notification System without websockets & polling - Just simple JSON?

I'm trying to build a real-time notification system without the use of Websockets or Polling, in the most efficient and fastest manner with no lags, and which costs the least UX

61
Mysql Select query to get data from three table

Mysql Select query to get data from three table

I have three table like below Table name : word

23
How to fetch data from two join tables with same database column names in codeigniter?

How to fetch data from two join tables with same database column names in codeigniter?

There are two tables 'student' and 'parent'both tables have 'f_name' and 'l_name' columns

33
PHP empty session files generated

PHP empty session files generated

I have a site where I use session authorization for my users Details are:

51