[英]HTTP response code after redirect to non-ascii domain name
如何获取所有用于域重定向到非ASCII域的标头?
域名www.sendevinci.co.il重定向到非ASCII域名www。מגשי-אירוח。co.il。
我的代码是:
$url = 'http://www.sendevinci.co.il'; $options['http'] = array( 'method' => "HEAD", 'ignore_errors' => 1, 'header' => "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\\r\\n" . "Accept-Language: en-US,en;q=0.8\\r\\n". "Keep-Alive: timeout=3, max=10\\r\\n", "Connection: keep-alive", 'user_agent' => self::get_user_agent_string($user_agent), "timeout" => 3 ); $context = stream_context_create($options); $body = file_get_contents($url, NULL, $context); print_r($http_response_header);
结果是:
Array ( [0] => HTTP/1.1 301 Moved Permanently [1] => Server: nginx [2] => Date: Thu, 07 Jun 2018 13:07:30 GMT [3] => Content-Type: text/html; charset=UTF-8 [4] => Connection: close [5] => X-Powered-By: PHP/7.2.6 [6] => Location: https://www.מגשי-אירוח.co.il [7] => X-Powered-By: PleskLin )
该阵列也应包括200个状态,但不包括200个状态。
该代码对于将ascii名称域重定向到ascii名称域的效果很好。
感谢您的帮助!
在HTTP协议级别,带有位置标头的200响应代码没有意义。 您可以使用带有201或202的Location标头,但是通常3xx用于将客户端发送到新位置。 我认为您收到的答复是正确的。 项目符号形式的HTTP位置标头在以下情况下有效:
换句话说,您关于数组也应包含200个状态的主张是不正确的。 在示例中,服务器提供的HTTP状态代码为301。
实际上, file_get_contents
仅适用于ascii域名。 因此,没有简单的解决方案来获取所有http标头...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.