【问题标题】:Cross domain issue, GET converted to OPTIONS跨域问题,GET 转换为 OPTIONS
【发布时间】:2026-02-05 08:50:02
【问题描述】:

我有以下请求和响应。访问允许控制来源设置为 *。

Remote Address:xx.xxx.xxx.xxx:xx
Request URL:http://api-test.example.com/api/v1/sample
Request Method:OPTIONS
Status Code:405 Method Not Allowed
Request Headersview source
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:max-age=0
Connection:keep-alive
Host:api-test.example.com
Origin:http://test.example.com
Referer:http://test.example.com/Joblist.html
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like GeChrome/34.0.1847.116 Safari/537.36

回复:

Response Headersview source
Access-Control-Allow-Methods:GET,PUT,POST,DELETE,OPTIONS
Access-Control-Allow-Origin:http:*
Allow:GET
Cache-Control:no-cache
Connection:keep-alive
Content-Length:76
Content-Type:application/json; charset=utf-8
Date:Tue, 15 Apr 2014 07:38:32 GMT
Expires:-1
Pragma:no-cache
Server:Microsoft-IIS/8.5
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET

我使用了 GET 方法,但它正在转换为 OPTIONS,如何解决这个问题?

这里是调用函​​数:

$.ajax({ 
type: "GET", 
url: "api-test.example.com/api/v1/sample";, 
headers:{Authorization:authHeader}, 
dataType: "xml", 
success: function(xml) { 

【问题讨论】:

  • “我已经使用了GET方法”然后显示它
  • $.ajax({ type: "GET", url: "api-test.example.com/api/v1/sample", headers:{Authorization:authHeader}, dataType: "xml", success: function(xml) {跨度>
  • 这应该可以帮助你jQuery CORS Content-type OPTIONS
  • @user3393032 url: "api-test.example.com/api/v1/sample";, 你有一个 ;这里。不知道是否与问题有关。

标签: jquery ajax html jquery-mobile cors


【解决方案1】:

看看我的回答here...

只要跨源请求中存在非简单标头,浏览器就会优先发送OPTIONS 请求。当这个OPTIONS 请求被发送到服务器时,服务器必须以允许的标头、方法和来源进行响应,以满足预检请求(并允许发出实际请求)。

Access-Control-Allow-Origin:http:*

http:* 不符合允许的来源。它只支持 *、null 或确切的域。

here is some info

【讨论】: