我正试图从cordova向龙卷风发送JSON,源代码在.js文件上,如下所示:
$http.post('http://localhost:81/api/login/validate', {
user: user,
password: password,
}).success(function(response) {
$scope.loginValidate = response;
});
然后.py文件管理处理程序请求:
类BaseHandler(tornado.web.RequestHandler):
def set_default_headers(self):
origin = self.request.headers.get('Origin', '*')
if origin == 'null':
origin = '*'
SUPPORTED_METHODS = ("CONNECT", "GET", "HEAD", "POST", "DELETE", "PATCH", "PUT", "OPTIONS")
self.set_header("Access-Control-Max-Age", "1728000")
self.set_header("Access-Control-Allow-Origin", "*" )
self.set_header("Access-Control-Allow-Methods", "GET,PUT,POST,OPTIONS,DELETE")
self.set_header("Access-Control-Allow-Headers", "Content-Type, Authorization, Content-Length, X-Requested-With") # , application/json -Json
self.set_header("Content-Type", "application/json")
但我得到一个不允许的错误405方法,代码工作正常whitjs,但在cordova上运行时它显示错误。
此外我已经安装了白名单API,配置如下的config.xml文件:
<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
和package.json这样:
"proxy": [
{
"path": "/api",
"proxyUrl": "http://192.168.10.246:81/api/*"
}
],
"defaultBrowser": "firefox",