您好,我是laravel的新手,遇到一些奇怪的情况:
在laravel api.php中,我有路线
Route::get('/blog', function() {
$url_query_string = "format=json";
$request_url = 'https://www.squarespace.com/templates/?' . $url_query_string;
$ch = curl_init($request_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_USERAGENT, 'H.H\'s PHP CURL script');
$response_body = curl_exec($ch);
curl_close($ch);
$res = json_decode($response_body,true);
echo json_encode($res);
});
因此它可以正常工作,但无法提供经过验证的json,因此无法正确查看图片
不确定哪里出了问题?
答案 0 :(得分:0)
我解决了添加header('Content-Type: application/json');
$res = json_decode($response_body,true);
header('Content-Type: application/json');
echo json_encode($res);