此代码登录 Facebook,获取应用程序登录令牌,然后使用安全 HTTP POST 来使用图形 API 删除多个对象。
如果您需要做更奇特的事情,您也可以。
$context = stream_context_create(array('http' => array(
// set HTTP method
'method' => 'GET',
'user_agent' => "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6 (.NET CLR 3.5.30729)",
'max_redirects' => 0
)));
// extract the cookies
$fp = fopen(URL, "r", false, $context);
$meta = stream_get_meta_data($fp);
$headers = $metadata['wrapper_data'];
fclose($fp);
将记录 将获取 URL 返回的标头。不需要外部库。
I would recommend using PHP's stream contexts with the built in functions: https://www.php.net/manual/en/book.stream.php . Full HTTP/S functionality and integrates nicely with fopen/file_get_contents functions. You can (for example) do a POST like this:
Writing and parsing HTTP headers over the bare metal of a socket is insane, and I find curl's API to be downright offensive.
Take a look at PEAR's HTTP_Request2, it's probably even installed on your machine. And if not, you can just bundle it in with your code -- it's BSD licensed. It wraps either sockets or curl, and provides a relatively sane HTTP interface.
I'm looking into this right now and came across the following page which gives code for testing different options and producing speed outputs. Very interesting.
发布评论
评论(4)
我建议使用 PHP 的流上下文和内置函数: https://www .php.net/manual/en/book.stream.php 。完整的 HTTP/S 功能,并与
fopen
/file_get_contents
函数完美集成。例如,您可以执行如下 POST:此代码登录 Facebook,获取应用程序登录令牌,然后使用安全 HTTP POST 来使用图形 API 删除多个对象。
如果您需要做更奇特的事情,您也可以。
将记录 将获取 URL 返回的标头。不需要外部库。
I would recommend using PHP's stream contexts with the built in functions: https://www.php.net/manual/en/book.stream.php . Full HTTP/S functionality and integrates nicely with
fopen
/file_get_contents
functions. You can (for example) do a POST like this:This code logs into Facebook, fetches an App Login token and then uses a secure HTTP POST to delete a number of objects using the graph API.
If you need to do fancier things, you can as well.
Will log Will fetch you the headers returned by the URL. No external libraries required.
都不是。我的意思是,不直接。
在裸露的套接字上写入和解析 HTTP 标头是疯狂的,而且我发现curl 的 API 是彻头彻尾令人反感的。
看看 PEAR 的 HTTP_Request2,它甚至可能安装在您的计算机上。如果没有,您可以将其与您的代码捆绑在一起——它是 BSD 许可的。它包装套接字或curl ,并提供相对合理的HTTP接口。
Neither. Not directly, I mean.
Writing and parsing HTTP headers over the bare metal of a socket is insane, and I find curl's API to be downright offensive.
Take a look at PEAR's HTTP_Request2, it's probably even installed on your machine. And if not, you can just bundle it in with your code -- it's BSD licensed. It wraps either sockets or curl, and provides a relatively sane HTTP interface.
当你必须处理http协议时使用Curl,当你需要对非http服务器进行更通用的访问时使用socket。
Use Curl when you have to handle http protocol, and socket when you need a more generic access to non http server.
我现在正在研究这个问题,并发现了以下页面,其中提供了用于测试不同选项并生成速度输出的代码。非常有趣。
http://www.hashbangcode.com/blog/quickest-way -下载网页-php
I'm looking into this right now and came across the following page which gives code for testing different options and producing speed outputs. Very interesting.
http://www.hashbangcode.com/blog/quickest-way-download-web-page-php