【问题标题】:Sending array in header with Get, Put and Post methods [duplicate]使用 Get、Put 和 Post 方法在标头中发送数组 [重复]
【发布时间】:2016-03-27 22:27:43
【问题描述】:

大家! 我的问题是关于 HTTP 标头以及如何将我的数组发送到服务器。 我的数组是:

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

我想将带有 curl() 的数组发送到服务器,但在标头中,我在服务器中使用 slim。 我的客户端是:

$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);

我的服务器端是:

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() {/* ... */}

【问题讨论】:

  • 你的代码有什么问题? CURLOPT_url是复制错误,还是你在真实代码中有那个错误?
  • 您是在问如何读取服务器代码中的自定义标头吗?
  • 这是我的第二个问题。但现在我不知道如何用我的数组数据制作标题
  • 您可能需要查看文档以了解 CURLOPT_HTTPHEADER 接受的确切内容。

标签: php curl


【解决方案1】:

为什么你不能直接发布而不是尝试创建新的标题?

curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);

然后在另一边从$_POST 数组中获取您的数据

【讨论】:

  • 其实我之前是用 POSTFIELD 做的,但是我现在需要在 header 中用这三个方法发送我的数组。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多