请求POST改为选项挂起 [英] Request changed from POST to OPTIONS hangs

查看:350
本文介绍了请求POST改为选项挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图发送POST请求通过HTTPS端点。
要求有2头,内容类型(应用程序/ JSON)和apiKey。

I am trying to send a POST request to an endpoint over HTTPS. The request has 2 headers, content-type (application/json) and an apiKey.

我正在使用内置的一个角PhoneGap的应用程序的请求,并在发送请求的方法更改为可选项。

I am using the request in a PhoneGap application built in Angular, and when the request is sent its method is changed to OPTIONS.

我知道这是由于CORS浏览器的标准做法,但我有一个有效载荷,我需要服务器来取,而我的服务器家伙OPTIONS请求与CORS一个空的有效载荷说(虽然我找不到关于这个验证)。

I know this is standard practice for browsers due to CORS, but I have a payload which I need the server to take, and I'm told by the server guys that OPTIONS requests have an empty payload with CORS (although I can't find verification on this).

服务器设置了CORS和应该接受POST和选项。

The server is set up for CORS and should accept POST and OPTIONS.

出于某种原因,我的要求挂起。

For some reason my request hangs.

角code:

var submitDBIDResource = $resource(env.loginUserUrl, {}, {
    save: {
        method: 'POST',
        headers: { 'apiKey': apiKey }
     }
  });

submitDBIDResource.save({"dbid": dbid}).$promise.then(function(data) {
       console.log(data);
       return data;
   });

我在config.xml文件

I have in my config.xml file

任何想法我需要做什么?

Any ideas what I need to do?

感谢

推荐答案

浏览器发送POST请求之前,会自动发送一个OPTIONS请求。 OPTIONS请求必须以适当的响应,否则响应的浏览器将不会发送POST请求。

The browser will automatically send an OPTIONS request before it sends the POST request. The OPTIONS request must respond with the appropriate response or else the browser will not send the POST request.

您的后端家伙需要创建两个请求处理程序,一个用于选项和一个用于POST。

Your backend guys need to create two request handlers, one for the OPTIONS and one for the POST.

https://developer.mozilla.org/en-US/文档/网络/ HTTP / Access_control_CORS

这篇关于请求POST改为选项挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆