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() {/* ... */}
4
  • What's the problem with your code? Is CURLOPT_url a copying error, or do you have that mistake in the real code? Commented Dec 21, 2015 at 19:31
  • Are you asking how to read the custom headers in the server code? Commented Dec 21, 2015 at 19:32
  • thats my second question. but now i dont know how to make a header with my array-data Commented Dec 21, 2015 at 19:36
  • You might want to look at documentation for what exactly CURLOPT_HTTPHEADER accepts. Commented Dec 21, 2015 at 20:27

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Actually i did it with POSTFIELD befor, but i need now to send my array with this three methods in header.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.