I've tried searching, the other answers didn't help me.
I'm trying to send POST data via cURL, but it's only working on some servers. What gives?
I've tried:
if (!empty($data) && $usePost) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
$data contains an array with the key of products and the value of a JSON string.
I also tried explicitly using the query:
if (!empty($data) && $usePost) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
}
But still, $_POST on the receiving server gives me NULL.
Any idea what to do?
Here's the whole method:
public static function execCommand($command, $ch,$data=array(),$cookie_file='genCookie.txt', $usePost = false) {
$url = $command;
if (!empty($data) && !$usePost)
$url .= '?' . http_build_query($data);
elseif (isset($data['sessionid'])) {
$url .= '?sessionid=' . $data['sessionid'];
unset($data['sessionid']);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:21.0) Gecko/20100101 Firefox/21.0');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if (!empty($data) && $usePost) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
return curl_exec($ch);
}
I tried echoing $_REQUEST, so it's not in $_GET by mistake. I also tried file_get_contents('php://input'), but still nothing.
Both the sending and receiving ends are on Apache servers.
Bigger thing is, it's working on most servers, but only some are ignoring it. Is there a safer, more cross platform way to do this?