->header('Content-Type','text/plain'); }); 附加头信息至响应 大部分的响应方法都是可链式调用的,以使你更酣畅淋漓的创建响应实例。例如,你可以在响应返回给用户前使用header方法向响应实例中附加一系列的头信息: returnresponse($content) ->header('Content-Type',$type) ...
Route::get('home', function () { return response('Hello World', 200) ->header('Content-Type', 'text/plain'); });附加头信息至响应#大部分的响应方法都是可链式调用的,以使你更酣畅淋漓的创建响应实例。例如,你可以在响应返回给用户前使用 header 方法向响应实例中附加一系列的头信息:...
If you need control over the response status and headers, but also need to return a view as the response content, you may use the view method:1return response()->view('hello', $data)->header('Content-Type', $type);Of course, if you do not need to pass a custom HTTP status code...
IlluminateHttpResponse (SymfonyComponentHttpFoundationResponse的子类)Laravel中对普通的非JSON响应的定义 通过prepareResponse中的逻辑可以看到,无论路由执行结果返回的是什么值最终都会被Laravel转换为成一个Response对象,而这些对象都是SymfonyComponentHttpFoundationResponse类或者其子类的对象。从这里也就能看出来跟Request一样...
1return response($content) 2 ->header('Content-Type', $type) 3 ->header('X-Header-One', 'Header Value') 4 ->header('X-Header-Two', 'Header Value');Or, you may use the withHeaders method to specify an array of headers to be added to the response:...
A Response instance inherits from the Symfony\Component\HttpFoundation\Response class, which provides a variety of methods for building HTTP responses:Route::get('/home', function () { return response('Hello World', 200) ->header('Content-Type', 'text/plain'); });...
Route::get("custom/response",function(){ $response=Response::make("hello world"); $response->headers->set('Content-type','text/plain'); return $response; }); 如果需要访问Response类的方法,但又要返回一个视图作为响应的内容,通过使用Response::view方法可以很容易实现: returnResponse...
return response($content,$status)->header('Content-Type',$value) ->withCookie('site','LaravelAcademy.org',30,'/','laravel.app'); }); 注:withCookie方法实际上是调用了全局帮助函数cookie生成cookie,然后将cookie放到响应头中。 再次在浏览器中访问,F12查看cookie信息如下: ...
Route::get('testResponseCookie',function(){ $content = 'Hello LaravelAcademy!'; $status = 200; $value = 'text/html;charset=utf-8'; //设置cookie有效期为30分钟,作用路径为应用根目录,作用域名为laravel.app return response($content,$status)->header('Content-Type',$value) ...
'content-type': 'multipart/form-data', 'responseType': 'blob', 'X-CSRF-TOKEN': csrfToken } }; axios.post(downloadRoute, payload, config).then(response => { const downloadUrl = window.URL.createObjectURL(new Blob([response.data.fileOutput])); ...