
下面是 http://和https://传输的上下文选项列表
| method | 远程服务器支持的HTTP方法。默认为GET。 |
| header | 在请求期间发送的附加头信息。 |
| user_agent | 与User-Agent:头信息一起发送的值。默认情况下使用user_agent php.ini设置。 |
| content | 在头信息之后发送的附加数据。通常与POST或PUT请求一起使用。 |
| proxy | 指定代理服务器地址的URI。 |
| request_fulluri boolean | 当设置为TRUE时,在构建请求时将使用整个URI。默认为FALSE。 |
| follow_location | 跟随Location头信息的重定向。设置为0以禁用。默认为1。 |
| max_redirects | 要跟随的最大重定向次数。 |
| protocol_version | HTTP协议版本。默认为1.0。 |
| timeout | 以秒为单位的读取超时,由浮点数指定(例如10.5)。 |
| ignore_errors | 即使在失败状态码上也获取内容。默认为FALSE。 |
以下示例从http:// URL获取头信息和内容
<?php
$url = "http://localhost/testscript.php";
$opts = array('http' =>
array(
'method' => 'GET',
'max_redirects' => '0',
'ignore_errors' => '1'
);
$context = stream_context_create($opts);
$stream = fopen($url, 'r', false, $context);
var_dump(stream_get_meta_data($stream));
?>这将显示标题信息和元数据如下 −
array(10) {
["timed_out"]=>
bool(false)
["blocked"]=>
bool(true)
["eof"]=>
bool(false)
["wrapper_data"]=>
array(7) {
[0]=>
string(15) "HTTP/1.1 200 OK"
[1]=>
string(35) "Date: Thu, 17 Sep 2020 07:04:47 GMT"
[2]=>
string(55) "Server: Apache/2.4.41 (Win64) OpenSSL/1.0.2s PHP/7.1.32"
[3]=>
string(24) "X-Powered-By: PHP/7.1.32"
[4]=>
string(17) "Content-Length: 0"
[5]=>
string(17) "Connection: close"
[6]=>
string(38) "Content-Type: text/html; charset=UTF-8"
}
["wrapper_type"]=>
string(4) "http"
["stream_type"]=>
string(14) "tcp_socket/ssl"
["mode"]=>
string(1) "r"
["unread_bytes"]=>
int(0)
["seekable"]=>
bool(false)
["uri"]=>
string(31) "http://localhost/testscript.php"
}以上就是PHP HTTP上下文选项的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号