RequestResponse(laravel)
生活随笔
收集整理的這篇文章主要介紹了
RequestResponse(laravel)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Request
URL
// url: http://xx.com/aa/bb Request::url();// 路徑: /aa/bb Request::path();// 獲取請求 Uri: /aa/bb/?c=d Request::getRequestUri();// 獲取 Uri: http://xx.com/aa/bb/?c=d Request::getUri();// 獲取查詢字符串: c=d Request::getQueryString();// 判斷當前請求的 URI 是否可被匹配 Request::is('foo/*');請求內(nèi)容
// 返回用戶的 IP Request::ip();// 獲取請求端口 (例如 80, 443 等等) Request::getPort();// 從請求中取回頭部信息 Request::header('Content-Type'); // 從請求中取回服務器變量 Request::server('PATH_INFO');// 判斷 HTTP Content-Type 頭部信息是否包含 */json Request::isJson(); // 判斷請求是否是 AJAX 請求 Request::ajax();// 判斷請求是否使用 HTTPS Request::secure();// 獲取請求方法 Request::method(); // 判斷請求方法是否是指定類型的 Request::isMethod('post');請求參數(shù)
//獲取所有參數(shù) $request->all();//獲取部分輸入值,可使用only方法 $request->only('name','id');// 要排除部分輸入?yún)?shù)值$request->except('id');// 獲取請求輸入 $request->input('id',1); $request->input('test.0.name');// 判斷輸入?yún)?shù)名是否存在 $request->has('name')//請求數(shù)據(jù)暫時保存到session中 $request->flash();// 在當前請求獲取session中保存的數(shù)據(jù) $request->old();Response
// 創(chuàng)建一個回應且修改其頭部信息的值 $response = Response::make($contents, 200); $response->header('Content-Type', 'application/json'); return $response; // Response實例上的withCookie方法新增cookie $response=new Response; //第一個參數(shù)是cookie名,第二個參數(shù)是cookie值,第三個參數(shù)是有效期(分鐘) $response->withCookie(cookie('web','hjy',1)); // cookie()長期使用 $response->withCookie(cookie()->forever('name','hjy'));// 相應ajax return $response()->ajax($datas);?
轉(zhuǎn)載于:https://www.cnblogs.com/yunchuang96/p/7515514.html
總結
以上是生活随笔為你收集整理的RequestResponse(laravel)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 创建型设计模式(单例模式)
- 下一篇: Xshell 命令后台执行