2012-04-14 33 views
0

我需要一点帮助,从drupal代码移植一个函数。file_get_contents从drupal_http_request移植

我已经发现了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 

林想知道是否有人可以帮助我移植它。

感谢

回答

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); 
+0

唉唉,这是有道理...感谢,这并不需要数组作为第二个参数:) – BigJobbies 2012-04-14 18:45:41