简体   繁体   English

Http POST请求获取标头和正文

[英]Http POST request get headers and body

I am currently using the below mentioned code to make http post request and it only returns body. 我目前正在使用下面提到的代码来发出http发布请求,并且它仅返回正文。 I want the body and headers both. 我想要正文和标题。 How I can I get body and headers both with file_get_content method or CURL? 如何使用file_get_content方法或CURL获取正文和标头?

    $sURL = "url";
$sPD = "data";
$aHTTP = array(
  'http' => 
    array(
    'method'  => 'POST', 
    'header'  => "Content-Type: application/atom+xml"
    'content' => $sPD
  )
);
$context = stream_context_create($aHTTP);
$contents = file_get_contents($sURL, false, $context);

echo $contents;

Try: 尝试:

$context  = stream_context_create($aHTTP);
$stream   = fopen($sURL, 'r', false, $context);

$contents = stream_get_contents($stream);
$metadata = stream_get_meta_data($stream);

You can also use the HTTP Functions if available. 您也可以使用HTTP功能(如果有)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM