跨域请求
如果某个路由或分组需要支持跨域请求 可以使用
Route::get('new/:id', 'News/read')->ext('html')->allowCrossDomain();
跨域请求一般会发送一条
OPTIONS
的请求 一旦设置了跨域请求的话 不需要自己定义OPTIONS
请求的路由 系统会自动加上。
跨域请求系统会默认带上一些Header 包括:
Access-Control-Allow-Origin:*Access-Control-Allow-Methods:GET, POST, PATCH, PUT, DELETEAccess-Control-Allow-Headers:Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With
你可以添加或更改Header信息 使用
Route::get('new/:id', 'News/read')->ext('html')->header('Access-Control-Allow-Origin','thinkphp.cn')->header('Access-Control-Allow-Credentials', 'true')->allowCrossDomain();
尊贵的董事大人
英文标题不为空时 视为本栏投稿
需要关键字 描述 英文标题