我想知道从API请求json字符串时默认的Content-Type
标题选项是什么。file_get_contents默认标题
我注意到,即使要求Content-Type
是application/json
响应头Content-Type
将text/html
的file_get_contents是否自动设置标题基于其请求或者它有一个始终使用一个默认的?
我想知道从API请求json字符串时默认的Content-Type
标题选项是什么。file_get_contents默认标题
我注意到,即使要求Content-Type
是application/json
响应头Content-Type
将text/html
的file_get_contents是否自动设置标题基于其请求或者它有一个始终使用一个默认的?
file_get_contents
是否根据请求的内容自动设置标题,或者它是否具有始终使用的默认标题?
我认为没有默认值。对于context
参数你阅读下面,看看在docs的4个例子:有stream_context_create()
创建
一个有效的上下文资源。如果您不需要使用自定义上下文,则可以通过NULL跳过此参数。
使用Wireshark进行测试。
PHP 5.5.8发送:
POST /路径HTTP/1.0
主机:example.com
的Content-Length:[适当数量]
内容类型:application/x-www-form-urlencoded
对于fol降低上下文:
$options = array(
'http' => array(
'method' => 'POST',
'content' => $content
)
);
$context = stream_context_create($options);
*响应*标头由联系的webserver/script/API而不是'file_get_contents'设置。 – mario
@mario所以即使我添加上下文到file_get_contents它不会做出不同的? –
因为您似乎可以请求您希望返回api的内容类型。 –