我需要一些帮助从drupal代码移植函数。
我发现drupal_http_request基本上是file_get_contents,但是当我改变它时,我似乎得到了错误,
原始的drupal代码如下:
$response = drupal_http_request($url, array('Content-Type' => 'text/xml'), 'POST', $post_data);
基本上所有我正在做的就是替换它,所以它看起来像这样
$response = file_get_contents($url, array('Content-Type' => 'text/xml'), 'POST', $post_data);
当我运行这个时...我收到以下错误消息
file_get_contents() expects parameter 2 to be boolean
我想知道是否有人可以帮助我移植它。
由于
答案 0 :(得分:1)
file_get_contents
不会将数组作为第二个参数,请参阅http://php.net/manual/en/function.file-get-contents.php以获取详细示例
$opts = array (
'http' => array (
'method' => "POST",
'header' => 'Content-Type: text/xml\r\n',
'content' => $post_data
)
);
$context = stream_context_create ( $opts );
$data = file_get_contents ( $url, false, $context );