如何在PHP中发送HTTP请求和检索响应(通过微调标头)?

yeg*_*256 1 php

我必须向URL发送HTTP请求并与标头一起检索响应.我不仅对页面内容感兴趣,而且对所有标题也感兴趣.什么是最佳解决方案?插座?PEAR库不可访问,PHP配置不可编辑.

Rag*_*geZ 8

你应该使用 curl

文档中的快速示例

<?php
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.perdu.com/");
curl_setopt($ch, CURLOPT_HEADER, 1);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
?>
Run Code Online (Sandbox Code Playgroud)