如何从HTTP状态代码获取HTTP状态文本?

问题描述 投票:0回答:1

是否有任何标准功能(或在curl中,是Guzzle)从HTTP状态代码号获取HTTP状态文本/描述?

getHttpStatusText(404) === 'Not Found'

我知道我可以像这样创建地图

[
    ...
    404 => 'Not Found',
    ...
]

但是我认为某个地方应该已经有标准功能了?

php libcurl php-7 guzzle
1个回答
0
投票

在Guzzle中找到了它(这是我真正需要的地方:]

http://docs.guzzlephp.org/en/stable/quickstart.html#using-responses

$response->getReasonPhrase()

这里也是具有所有状态的关联数组:

https://github.com/guzzle/psr7/blob/12f6fcd48192c390c00856f5570335b9e6aab081/src/Response.php#L18

© www.soinside.com 2019 - 2024. All rights reserved.