【问题标题】:Http POST request get headers and bodyHttp POST 请求获取标头和正文
【发布时间】:2015-02-18 18:02:21
【问题描述】:

我目前正在使用下面提到的代码来发出 http post 请求,它只返回正文。我想要正文和标题。如何使用 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;

【问题讨论】:

    标签: php post curl http-headers


    【解决方案1】:

    试试:

    $context  = stream_context_create($aHTTP);
    $stream   = fopen($sURL, 'r', false, $context);
    
    $contents = stream_get_contents($stream);
    $metadata = stream_get_meta_data($stream);
    

    如果可用,您也可以使用HTTP Functions

    【讨论】:

      猜你喜欢
      • 2023-03-04
      • 2018-05-10
      • 1970-01-01
      • 2020-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-03
      相关资源
      最近更新 更多