file_get_contents 默认 headers
file_get_contents Default headers
我想知道从 API.
请求 json 字符串时默认的 Content-Type
header 选项是什么
我注意到即使请求的 Content-Type
是 application/json
,响应 header Content-Type
也会是 text/html
file_get_contents 是根据请求自动设置 header 还是有一个始终使用的默认设置?
Does file_get_contents
set the headers automatically based on what it is requesting or does it have a default one that is used always?
我认为没有默认值。对于 context
参数,您在下面阅读并查看 docs 中的第 4 个示例:
A valid context resource created with stream_context_create()
. If you don't need to use a custom context, you can skip this parameter by NULL.
使用 Wireshark 测试。
PHP 5.5.8 发送:
POST /path HTTP/1.0
Host: example.com
Content-Length: [appropriate number]
Content-Type: application/x-www-form-urlencoded
对于以下上下文:
$options = array(
'http' => array(
'method' => 'POST',
'content' => $content
)
);
$context = stream_context_create($options);
我想知道从 API.
请求 json 字符串时默认的Content-Type
header 选项是什么
我注意到即使请求的 Content-Type
是 application/json
,响应 header Content-Type
也会是 text/html
file_get_contents 是根据请求自动设置 header 还是有一个始终使用的默认设置?
Does
file_get_contents
set the headers automatically based on what it is requesting or does it have a default one that is used always?
我认为没有默认值。对于 context
参数,您在下面阅读并查看 docs 中的第 4 个示例:
A valid context resource created with
stream_context_create()
. If you don't need to use a custom context, you can skip this parameter by NULL.
使用 Wireshark 测试。
PHP 5.5.8 发送:
POST /path HTTP/1.0
Host: example.com
Content-Length: [appropriate number]
Content-Type: application/x-www-form-urlencoded
对于以下上下文:
$options = array(
'http' => array(
'method' => 'POST',
'content' => $content
)
);
$context = stream_context_create($options);