需要在我的应用中两次请求一些代码。拳头将URL作为ajax调用,并且还需要在控制器中请求此URL(类似于hmvc)。我知道如何通过curl开发它,但是我发现了另一种实现方法,只是在准备好参数之前使用file_get_contents函数。这是我的代码:
// Setup limit per page
$args['offset'] = $offset;
$args['limit'] = $this->_perpage;
// --
// Convert search arguments to the uri format
$data = http_build_query($args);
// Define request params
$options = array(
'http' => array(
'header' => 'Content-type: application/json' . PHP_EOL .
'Content-Length: ' . strlen($data) . PHP_EOL,
'method' => 'POST',
'content' => $data,
),
);
$context = stream_context_create($options);
$result = file_get_contents(
'http://'.$_SERVER['HTTP_HOST'].'/search/items', FALSE, $context
);
在请求的uri中检测到请求方法正常,但未传递参数。为什么这不是传递参数来请求?我的代码中的错误在哪里?非常感谢您提供任何答案。
http_build_query生成application / x-www-form-urlencoded内容。(不是application / json)
有一个完整的例子:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句