- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 CORS 预检成功返回 200 状态后,我遇到了 302 重定向问题。我目前正在使用 Laravel 4.1 和 Angular 1.2 以及我自己的 OAUTH2 服务器构建一个应用程序。
Chrome/FF/Safari 发回给我的错误是:
XMLHttpRequest cannot load
http://localhost.api/api/v1/tracks?$filter=id%20eq%20guid%27d7de10ba-e353-455b-a3cb-ced9b4965141%27&
. The request was redirected to 'http://localhost.api/session/invalid
', which is disallowed for cross-origin requests that require preflight.
我认为导致我的问题的是正在发生的“重定向” - 因为我的正常 CORS 要求所有工作按预期进行。
我的 Access-Control-Allow-* header 的配置现在在测试期间相当开放。
'paths' => array(
'^/api/' => array(
'allow_origin'=> array('*'),
'allow_headers'=> array('Content-Type', 'Authorization'),
'allow_methods'=> array('POST', 'PUT', 'GET', 'DELETE', 'OPTIONS'),
'max_age' => 0
),
'^/session/' => array(
'allow_origin'=> array('*'),
'allow_headers'=> array('Content-Type', 'Authorization'),
'allow_methods'=> array('GET', 'OPTIONS'),
'max_age' => 0
)
有问题的重定向位于检查 OAUTH2 访问 token 有效性的预过滤器中
public function filter($route, $request, $data = null)
{
// Get the authorization header or fail
if ($authorization = Request::header('Authorization', false)) {
list($type, $token) = explode(' ', $authorization);
if (is_null($auth = OAuth2::token($token)->first())) {
return Redirect::to('session/invalid');
}
$tokenExpiryDate = Carbon::createFromTimeStamp($auth->access_token_expires);
// If we don't have a Bearer authentication header
// or if the token has expired. Then redirect to an
// expired session route
if ( 'bearer' != strtolower($type)
|| Carbon::now()->gt($tokenExpiryDate)
) {
return Redirect::route(
'expiredSession',
array('expiry' => $tokenExpiryDate->timestamp)
);
}
} else {
// The authentication header is invalid, redirect to let the user know.
return Redirect::to('session/invalid');
}
}
当我尝试使用 POSTMAN 进行调试时,所有这些请求都有效,但经过研究,我基本上发现扩展不一定必须遵循相同的规则。我还注意到,当我发起简单的 GET、POST 等操作时,使用 POSTMAN 的请求从不发送任何预检选项请求。
以下是 OPTIONS 请求的 header 以及跟随该请求并返回错误的 GET 请求的 header
Remote Address:127.0.0.1:80
Request URL:http://localhost.api/api/v1/tracks?$filter=id%20eq%20guid%27d7de10ba-e353-455b-a3cb-ced9b4965141%27&
Request Method:OPTIONS
Status Code:200 OK
请求 header
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:accept, authorization
Access-Control-Request-Method:GET
Cache-Control:no-cache
Connection:keep-alive
DNT:1
Host:vegas.ine.com
Origin:http://localhost.angular
Pragma:no-cache
Referer:http://localhost.angular/admin/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36
响应 header
Access-Control-Allow-Headers:content-type, authorization
Access-Control-Allow-Methods:POST, PUT, GET, DELETE, OPTIONS
Access-Control-Allow-Origin:http://localhost.angular
Cache-Control:no-cache
Connection:close
Content-Type:text/html
Date:Thu, 01 May 2014 16:22:19 GMT
Server:Apache/2.2.26 (Unix) DAV/2 PHP/5.4.24 mod_ssl/2.2.26 OpenSSL/0.9.8y
Set-Cookie:laravel_session=eyJpdiI6IktOZjlTM1ZVNUx0TEhoaTczY3dQcDBKRWlvbnppbDA3QTdqSENJdTc2R1U9IiwidmFsdWUiOiJEZ2ltXC9mNm1Qa20rV3BVRlNHTXgySGtUeVlpNjNZcGFudDFBWDJJekl1MEVNVlhSRE5WWk5YZDNxUkZuU0VEVytcL3NLNlVBXC9hZWtJQzdHU2FqVWtMdz09IiwibWFjIjoiYTYxYjEwNjlmYmI2MjMwNmE4MzlkYjIwNGZlNzA4Y2ViZGVkZmU1MTQzMzc5NmU2YzI2ZGExNzYxY2U5ZjdiMCJ9; expires=Thu, 01-May-2014 18:22:19 GMT; path=/; httponly
X-Frame-Options:SAMEORIGIN
X-Powered-By:PHP/5.4.24
Remote Address:127.0.0.1:80
Request URL:http://localhost.api/api/v1/tracks?$filter=id%20eq%20guid%27d7de10ba-e353-455b-a3cb-ced9b4965141%27&
Request Method:GET
Status Code:302 Found
请求 header
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Authorization:Bearer 6Ss4XPrPM5jQD7Es0dz7TPRQ76hGA69vT9K94pst
Cache-Control:no-cache
Connection:keep-alive
DNT:1
Host:vegas.ine.com
Origin:http://localhost.angular
Pragma:no-cache
Referer:http://localhost.angular/admin/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36
响应 header
Access-Control-Allow-Origin:http://localhost.angular
Cache-Control:no-cache
Connection:Keep-Alive
Content-Type:text/html; charset=UTF-8
Date:Thu, 01 May 2014 16:22:19 GMT
Keep-Alive:timeout=5, max=100
Location:http://localhost.api/session/invalid
Server:Apache/2.2.26 (Unix) DAV/2 PHP/5.4.24 mod_ssl/2.2.26 OpenSSL/0.9.8y
Set-Cookie:laravel_session=eyJpdiI6InlnREVPcUJTcyswMnRLanFDSlZ6QWFBVXZWMGdMNVNLYWxNTHRJVUlkalk9IiwidmFsdWUiOiJ4aXN5U0dcL1NYeGQrcUVzWFhYV3o2MWhcL25hQTlhcVUxbWxkN2R6SG9KZDNKaGNLTkRQY2FyTitpVHNGZzYxVVRtZUhoZGZRWE9GWjZRaDd1VVwvZUZuUT09IiwibWFjIjoiY2EzZTViZGIzZmVlMDcwZjdhMzBjOWQxYTgwZWNlYTJiMDk3ODdlZTk3NTYxMDNmM2YyODJjOGIxMzBmMmJlMiJ9; expires=Thu, 01-May-2014 18:22:20 GMT; path=/; httponly
Transfer-Encoding:chunked
Vary:Authorization
X-Clockwork-Id:1398961340.2239.1349476325
X-Clockwork-Version:1.5
X-Frame-Options:SAMEORIGIN
X-Powered-By:PHP/5.4.24
最佳答案
我做过类似的事情,它对我来说效果很好
//pattern to allow origins
$allowedOriginPattern = /** YOUR PATTERNS **/;
$allowedOrigin = "";
if (preg_match($allowedOriginPattern, $_SERVER['HTTP_ORIGIN'])) {
$allowedOrigin = $_SERVER['HTTP_ORIGIN'];
}
/**
* set http content type
*/
header('Content-Type: application/json;charset=UTF-8');
header('Access-Control-Allow-Origin: ' . $allowedOrigin);
header('Access-Control-Allow-Methods: DELETE, HEAD, GET, OPTIONS, POST, PUT');
header('Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description');
header('Access-Control-Max-Age: 1728000');
我已在 laravel index.php 中添加了此代码
这里是CORS的引用 http://www.w3.org/TR/cors/#cross-origin-request-with-preflight-0
关于redirect - CORS 预检后 302 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23412037/
我想知道的区别按照重定向 和 自动重定向 使用 Jmeter 录制时。 当与 一起使用时,这两者会有什么影响?从 HTML 中检索所有嵌入的资源 最佳答案 Redirect automatically
我正在编写一个 WordPress 插件,它添加了一个管理菜单页面。页面中有一个表格。提交表单后,插件将写入数据库。但后来我遇到了一个问题:每当用户重新加载页面时,都会询问他/她是否再次发送 POST
我有两个扩展程序,我想在某个操作中从一个扩展程序重定向到另一个扩展程序。这是我的 bpsmessagecentre 扩展的 bpsmessagecontroller 的 saveAction 中的重定
当我有这个命名路线时:Route::get('/', 'IndexController@index')->name('home'); 然后在任何 Controller 的任何 Action 方法中;当
我正在尝试设置 Lumen - 建立在 Laravel 组件之上的“微框架”。服务器端有 nginx + php-fpm。 这是我的 nginx 配置: server { server_nam
我是ASP.Net 4.0的新手,并且看到了一个名为Response.RedirectPermanent()的新功能。我检查了几篇文章,但是我无法清楚地理解Response.RedirectPerma
我想从路线 /new 重定向,并保留 new 的查询参数路线: 据我所知,唯一可以访问queryParams的地方位于model内路线的钩子(Hook)。 但我想重定向到 beforeModel ho
我在实现简单的HTTP重定向时遇到问题。 我使用Liferay 6.0.6,我们的 portlet 是使用 JSF2.0 /PortletFaces构建的。 我想在加载 View 时(而不是在触发操作
我正在尝试设置 NGINX 和 cloudflare。 我在谷歌上读过这个,但没有解决我的问题 .我的 cloudflare 目前处于事件状态。我删除了 cloudflare 中的所有页面规则,但之前
我有一个运行两个子域的 Nginx 服务器。其中一个使用 proxy_pass 将所有内容重定向到 Meteor 应用程序,另一个子域仅使用 Laravel,但位于与普通域不同的目录中。 因此,当我启
我想在注册后将用户重定向到另一个表单,然后他才能访问我网站上的任何内容(例如 https://github.com/FriendsOfSymfony/FOSUserBundle/issues/387
我有一个提交到详细信息页面的表单,其中有一个按钮。我在我的映射文件中放置了一个 Action 以将一个 Action 链接到该按钮,该按钮应将用户发送回表单并将其清空。 我可以正确地重定向它,但表单仍
我一直在谷歌上搜索这个,但似乎没有人知道答案。 这篇文章很好地描述了这个问题: http://www.mail-archive.com/php-general@lists.php.net/msg198
在 Sinatra 中使用 redirect 和 redirect to 有什么区别?他们似乎都默认为相同的状态代码。 to '/url' 位是否只是为了使方法更具可读性的一些语法上的好处? 最佳答案
这是一个可以抛出异常的示例按钮: 在我的 ExceptionHandler我有: FacesContext.getCurrentInstance().getExternalContext
我现在在同一家公司的多个网站上工作,每个网站都通过顶部标题上的链接列表连接到其他网站。 访问跟踪是通过谷歌分析完成的,一切似乎都运行良好。太糟糕了,他们现在似乎对附加在 url 底部以获得跨域跟踪的所
目前我正在开发一个项目,该项目在提交时对表单执行一些客户端验证(使用 Javascript),然后基于 Ajax 请求,或者进行 window.location.href 重定向或提交表单以供 Con
我将我的 Gitlab 迁移到了新域。我想将所有 HTTP 请求从旧 URL 重定向到新 URL。两个域当前都指向同一服务器(使用 A DNS 记录)。 我使用 Gitlab Omnibus 包,并捆
我想在每个以“/”结尾的文档中添加“.html”,但主页除外。 我尝试了一些不同的方法,使用 nginx 重写和返回 301,但我没有让它工作。附上我做的最后一个版本,它正在做/*/.html 但第二
我想在每个以“/”结尾的文档中添加“.html”,但主页除外。 我尝试了一些不同的方法,使用 nginx 重写和返回 301,但我没有让它工作。附上我做的最后一个版本,它正在做/*/.html 但第二
我是一名优秀的程序员,十分优秀!