JQuery Mobile, Cordova的跨域CORS请求
2016-10-20 06:42
274 查看
Cordova手机app中,大量使用JQuery Mobile, datatjs(OData)等js框架,他们都遵循W3C HTTP CORS标准,app发起HTTP GET/POST等请求外网资源的时候,JQuery会偷偷摸摸的先发个HTTP OPTIONS请求外网资源,外网服务器准许之后,JQuery才会正式的再发个HTTP GET/POST请求。
举例如下:
参考:
http://demos.jquerymobile.com/1.3.2/faq/how-configure-phonegap-cordova.html
节选:The initial application document is loaded by the PhoneGap application by a local file:// URL. This means that if you want to pull in pages from your company’s remote server (phone home) you will have to refer to them with absolute URLs to your server. Because your document originates from a file:// URL, loading pages or assets from your remote server is considered a cross-domain request that can be blocked in certain scenarios.
W3C HTTP CORS标准](https://www.w3.org/TR/cors/)
举例如下:
OPTIONS /odata/applications/latest/app1/Connections HTTP/1.1 Host: smp.springworks.info:8081 Connection: keep-alive Access-Control-Request-Method: POST Origin: file:// User-Agent: Mozilla/5.0 (Linux; Android 5.0.2; Redmi Note 3 Build/LRX22G; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/45.0.2454.95 Mobile Safari/537.36 Access-Control-Request-Headers: accept, authorization, content-type, dataserviceversion, maxdataserviceversion Accept: */* Accept-Encoding: gzip, deflate Accept-Language: zh-CN,en-US;q=0.8 X-Requested-With: com.mycompany.logon HTTP/1.1 200 OK Access-Control-Allow-Credentials: true Access-Control-Allow-Origin: file:// Access-Control-Allow-Methods: POST Access-Control-Allow-Headers: accept, authorization, content-type, dataserviceversion, maxdataserviceversion Access-Control-Max-Age: 3600 Content-Length: 0 Date: Wed, 19 Oct 2016 21:54:36 GMT Server: SAP POST /odata/applications/latest/app1/Connections HTTP/1.1 Host: smp.springworks.info:8081 Connection: keep-alive Content-Length: 2 Accept: application/json MaxDataServiceVersion: 3.0 Origin: file:// User-Agent: Mozilla/5.0 (Linux; Android 5.0.2; Redmi Note 3 Build/LRX22G; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/45.0.2454.95 Mobile Safari/537.36 DataServiceVersion: 1.0 Authorization: Basic dG9tY2F0OnRvbWNhdA== Content-Type: application/json Accept-Encoding: gzip, deflate Accept-Language: zh-CN,en-US;q=0.8 X-Requested-With: com.mycompany.logon HTTP/1.1 201 Created Access-Control-Allow-Credentials: true Set-Cookie: X-SMP-SESSIDSSO=B984633BCF2344F81A6F784362782724; Path=/; HttpOnly Set-Cookie: X-SMP-SESSID=29B2310D0600349CCBA294F7D7B851340121DBD6BD9A523EF08F1552CF25D566; Path=/; HttpOnly Set-Cookie: X-SUP-APPCID=41fc7dba-7c5e-4577-9184-12b95e89536e; Expires=Tue, 14-Oct-2036 21:54:36 GMT; Path=/ Set-Cookie: X-SMP-APPCID=41fc7dba-7c5e-4577-9184-12b95e89536e; Expires=Tue, 14-Oct-2036 21:54:36 GMT; Path=/ DataServiceVersion: 1.0 Date: Wed, 19 Oct 2016 21:54:36 GMT Location: http://smp.springworks.info:8081/odata/applications/latest/app1/Connections('41fc7dba-7c5e-4577-9184-12b95e89536e') Content-Type: application/json;charset=utf-8 Transfer-Encoding: chunked Content-Encoding: gzip Vary: Accept-Encoding Server: SAP
参考:
http://demos.jquerymobile.com/1.3.2/faq/how-configure-phonegap-cordova.html
节选:The initial application document is loaded by the PhoneGap application by a local file:// URL. This means that if you want to pull in pages from your company’s remote server (phone home) you will have to refer to them with absolute URLs to your server. Because your document originates from a file:// URL, loading pages or assets from your remote server is considered a cross-domain request that can be blocked in certain scenarios.
W3C HTTP CORS标准](https://www.w3.org/TR/cors/)
相关文章推荐
- 跨域请求解决方法(JSONP, CORS)
- 跨域请求CORS请求不能收到服务器返回的数据
- 跨域请求 JSONP & CORS
- Ajax请求的跨域(CORS)问题
- Nginx反向代理、CORS、JSONP等跨域请求解决方法总结
- Nginx反向代理、CORS、JSONP等跨域请求解决方法总结
- Spring boot通过过滤器使用CORS实现JavaWeb跨域请求
- 可以将资源移动到相同的域名上或者启用 CORS 来解决这个问题(跨域问题)、options请求报错
- Nginx反向代理、CORS、JSONP等跨域请求解决方法总结
- 快速解决跨域请求问题:jsonp和CORS
- cordova学习八 跨域请求
- 跨域请求问题 : jsonp & CORS
- Java实现CORS跨域请求的实现方法
- Java实现CORS跨域请求
- cors跨域请求,重复提交问题
- CORS解决跨域请求--html5
- react中fetch之cors跨域请求的实现方法
- Cors跨域请求,配置Access-Control-Allow-Origin:"*",无效解决方案
- 从零开始学 Java - Spring MVC 实现跨域资源 CORS 请求
- ASP.NET跨域请求中的问题【CORS】