php使用file_get_contents返回false, 具体报错内容如下:
failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
解决方式1 : 使用curl 替换 file_get_contents
解决方式2 : 请检查请求网址中是否包含中文, 将中文部分进行urlencode
function encodeChineseChars($url) {
$pattern = '/[\x{4e00}-\x{9fa5}]+/u';
$output = preg_replace_callback(
$pattern,
function ($matches) {
// 对匹配的汉字部分进行 urlencode
return urlencode($matches[0]);
},
$url
);
return $output;
}