您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

预检队列请求Preflight Queue Request

Preflight Queue Request 操作在发送实际请求之前,会先查询队列服务的跨域资源共享 (CORS) 规则。The Preflight Queue Request operation queries the Cross-Origin Resource Sharing (CORS) rules for the Queue service prior to sending the actual request. Web 浏览器或另一用户代理会发送一个预检请求,其中包含该代理希望发出的实际请求的源域、方法和标头。A web browser or another user agent sends a preflight request that includes the origin domain, method, and headers for the actual request that the agent wishes to make. 如果为队列服务启用了 CORS,则队列服务会根据帐户所有者通过设置队列服务属性配置的 CORS 规则评估预检请求,并接受或拒绝该请求。If CORS is enabled for the Queue service, then the Queue service evaluates the preflight request against the CORS rules that the account owner has configured via Set Queue Service Properties, and accepts or rejects the request.

有关 CORS 和预检请求的详细信息,请参阅存储服务的CORS 规范和 CORS 支持For more information about CORS and the preflight request, see the CORS specification and CORS Support for the Storage Services

请求Request

可以按以下方式指定 Preflight Queue RequestThe Preflight Queue Request may be specified as follows. <account-name> 替换为存储帐户的名称。Replace <account-name> with the name of your storage account. 使用将要用作实际请求的目标的队列资源的名称替换 <queue-resource>Replace <queue-resource> with the name of the queue resource that is to be the target of the actual request:

HTTP 谓词HTTP Verb 请求 URIRequest URI HTTP 版本HTTP Version
OPTIONSOPTIONS http://<account-name> .queue.core.windows.net/<queue-resource> HTTP/1.1HTTP/1.1

请注意,URI 必须始终包含正斜杠 (/),以将主机名与 URI 的路径和查询部分隔开。Note that the URI must always include the forward slash (/) to separate the host name from the path and query portions of the URI. 在执行此操作时,URI 的路径部分可以是空的,也可以指向任何队列资源。In the case of this operation, the path portion of the URI can be empty, or can point to any queue resource. 在发出预检请求时,资源可能存在,也可能不存在;将在服务级别根据服务的 CORS 规则评估预检请求,因此资源名称是否存在并不影响操作结果。The resource may or may not exist at the time the preflight request is made; the preflight request is evaluated at the service level against the service's CORS rules, so the presence or absence of the resource name does not affect the success or failure of the operation.

URI 参数URI Parameters

无。None.

请求标头Request Headers

下表介绍必需的和可选的请求标头。The following table describes required and optional request headers.

请求标头Request Header 说明Description
Origin 必需。Required. 指定将从中发出实际请求的来源。Specifies the origin from which the actual request will be issued. 将根据服务的 CORS 规则检查来源,以确定预检请求是成功还是失败。The origin is checked against the service's CORS rules to determine the success or failure of the preflight request.
Access-Control-Request-Method 必需。Required. 指定实际请求的方法(或 HTTP 谓词)。Specifies the method (or HTTP verb) for the actual request. 将根据服务的 CORS 规则检查该方法,以确定预检请求是成功还是失败。The method is checked against the service's CORS rules to determine the failure or success of the preflight request.
Access-Control-Request-Headers 可选。Optional. 指定将发送的实际请求标头,然后该服务假定没有随实际请求发送标头。Specifies the headers for the actual request headers that will be sent, then the service assumes no headers are sent with the actual request.

请求正文Request Body

无。None.

响应Response

响应包括 HTTP 状态代码和一组响应标头。The response includes an HTTP status code and a set of response headers.

状态代码Status Code

此操作成功后返回状态代码 200(正常)。A successful operation returns status code 200 (OK).

有关状态代码的信息,请参阅状态代码和错误代码For information about status codes, see Status and Error Codes.

响应标头Response Headers

此操作的响应包括以下标头。The response for this operation includes the following headers. 该响应还可能包括其他标准 HTTP 标头。The response may also include additional standard HTTP headers. 所有标准标头都符合HTTP/1.1 协议规范All standard headers conform to the HTTP/1.1 protocol specification.

有关预检请求标头的详细信息,请参阅CORS 规范See the CORS specification for details about preflight request headers.

响应标头Response Header 说明Description
访问控制-允许-原点Access-Control-Allow-Origin 允许的来源,如果预检请求成功,该来源将与请求中的来源标头匹配。The allowed origin, which matches the origin header in the request if the preflight request succeeded.
访问控制-允许方法Access-Control-Allow-Methods 如果预检请求成功,此标头将设置为针对请求标头 Access-Control-Request-Method 指定的值。If the preflight requests succeeds, this header is set to the value or values specified for the request header Access-Control-Request-Method.
访问控制-允许-标题Access-Control-Allow-Headers 如果预检请求成功,此标头将设置为针对请求标头 Access-Control-Request-Headers 指定的值。If the preflight request succeeds, this header is set to the value or values specified for the request header Access-Control-Request-Headers.
访问控制-最大年龄Access-Control-Max-Age 指定允许用户代理缓存预检请求以用于将来的请求的时间长度。Specifies the length of time the user agent is allowed to cache the preflight request for future requests.
访问控制允许凭据Access-Control-Allow-Credentials 指示是否可使用凭据发出实际请求。Indicates whether the actual request can be made using credentials. 此标头始终设置为 trueThis header is always set to true.

响应正文Response Body

无。None.

授权Authorization

操作Preflight Queue Request始终以匿名方式执行。The Preflight Queue Request operation always executes anonymously. 它不需要授权,如果提供凭据,则忽略凭据。It does not require authorization, and ignores credentials if they are provided.

备注

如果已启用 Azure 存储分析并记录指标,请注意,对Preflight Queue Request操作的调用将记录为 "匿名成功"。If you have enabled Azure Storage analytics and are logging metrics, note that a call to the Preflight Queue Request operation is logged as AnonymousSuccess. 因此,如果在 Azure 门户中查看指标,您将看到为 记录的Preflight Queue Request匿名成功For this reason, if you view metrics in the Azure portal, you will see AnonymousSuccess logged for Preflight Queue Request. 此指标不表示您的私有数据已泄露,但仅表示Preflight Queue Request操作成功,状态代码为 200 (OK)。This metric does not indicate that your private data has been compromised, but only that the Preflight Queue Request operation succeeded with a status code of 200 (OK).

示例请求和响应Sample Request and Response

下面的示例发送源www.contoso.com的预检请求,请求方法设置为PUT和 的请求标头设置为content-typeacceptThe following example sends a preflight request for the origin www.contoso.com, with the request method set to PUT and the request headers set to content-type and accept.

OPTIONS http://myaccount.queue.core.windows.net/myqueue  HTTP/1.1  
Accept: */*  
Origin: www.contoso.com  
Access-Control-Request-Method: PUT  
Access-Control-Request-Headers: content-type, accept  
Accept-Encoding: gzip, deflate  
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)  
Content-Length: 0  
  

响应指示已为服务启用 CORS,并且有一条 CORS 规则与预检请求相匹配。The response indicates that CORS is enabled for the service, and that a CORS rule matches the preflight request.

HTTP/1.1 200 OK  
Connection: Keep-Alive  
Content-Length: 0  
Content-Type: text/html; charset=UTF-8  
Access-Control-Allow-Origin: *  
Access-Control-Max-Age: 60  
Access-Control-Allow-Methods: PUT  
Access-Control-Allow-Headers: accept,content-type  
  

备注Remarks

如果为服务启用了 CORS,并且存在与预检请求匹配的 CORS 规则,那么该服务将使用状态代码 200 (OK) 响应预检请求。If CORS is enabled for the service and there is a CORS rule that matches the preflight request, the service responds to the preflight request with status code 200 (OK). 响应包含所需的 Access-Control 标头。The response includes the required Access-Control headers. 在此情况下将对该请求计费。In this case, the request will be billed.

如果未启用 CORS 或者不存在与预检请求匹配的 CORS 规则,服务将使用状态代码 403 (Forbidden) 进行响应。If CORS is not enabled or no CORS rule matches the preflight request, the service responds with status code 403 (Forbidden). 在此情况下将不对该请求计费。In this case, the request will not be billed.

如果 OPTIONS 请求格式不正确,服务将使用状态代码 400 (Bad Request) 进行响应,并且不对请求计费。If the OPTIONS request is malformed, the service responds with status code 400 (Bad Request) and the request is not billed. 不包含必需的 OriginAccess-Control-Request-Method 标头的请求就属于格式不正确的请求。An example of a malformed request is one that doesn’t contain the required Origin and Access-Control-Request-Method headers.

请注意,预检请求是一种查询与特定存储帐户关联的存储服务的 CORS 功能的机制。Note that the preflight request is a mechanism to query the CORS capability of a storage service associated with a certain storage account. 预检请求不针对某个特定资源。The preflight request is not targeted to a specific resource.

另请参阅See Also

帐户上的操作(队列服务) Operations on the Account (Queue Service)
对存储服务的 CORS 支持CORS Support for the Storage Services