[英]Http POST request get headers and body
我目前正在使用下面提到的代碼來發出http發布請求,並且它僅返回正文。 我想要正文和標題。 如何使用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;
嘗試:
$context = stream_context_create($aHTTP);
$stream = fopen($sURL, 'r', false, $context);
$contents = stream_get_contents($stream);
$metadata = stream_get_meta_data($stream);
您也可以使用HTTP功能(如果有)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.