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