0

everyone! my question is about HTTP headers and how to send my array to server. my array is :

$postdata = array(
    'user' => $user,
    'timestamp' => $timestamp,
    'hash' => $hash
);

i want to send my array with curl() to server but in header, and i use slim in my server. my client side is :

$url = 'localhost/test';

$ch = curl_init();
curl_setopt($ch, CURLOPT_url, $url);
curl_setopt($ch, RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $postdata);

$response = curl_exec($ch);

echo $response;
curl_close($ch);

My server side is :

require('slim/slim.php');

\slim\slim::registerAutoloader();

$app = new \slim\slim(array('debug' => true, 'mode' => 'development'));
$app->contentType('application/json;charset=utf-8');
$app-get('test', 'mockup');
$app->run();

function mockup() {/* ... */}
miken32
  • 42,008
  • 16
  • 111
  • 154
Nicky
  • 1
  • 2

1 Answers1

0

Why can't you just post it instead of trying to create new headers?

curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);

Then on the other side just get your data from the $_POST array

I wrestled a bear once.
  • 22,983
  • 19
  • 69
  • 116
  • Actually i did it with POSTFIELD befor, but i need now to send my array with this three methods in header. – Nicky Dec 21 '15 at 19:27