【问题标题】:google app engine python as backend and angular js as frontend for mobile webgoogle app engine python作为后端,angular js作为移动网络的前端
【发布时间】:2014-09-27 18:53:41
【问题描述】:

我正在尝试通过 python 和 angularJS 移动应用程序实现 GAE 之间的端到端数据共享,使用 JSON 作为来自移动设备的请求正文,contentType 作为应用程序/json。 我可以在我的日志中看到 GAE 正在接收数据并发送响应,即{'status': true}

我的 Firebug 控制台对我的 GAE 服务器的 POST 请求显示红色字体(错误),但响应状态为 200(正常)。移动应用收到 200 响应状态,但未获取数据。

在我的移动应用程序中,我使用 $http.post(url, data); 向 GAE 发出 http 请求,我在 Firebug 控制台中得到了这个:

POST http://<code>serverAddress_is_localhost_for_testing</code>:8080/serviceProvider

200 OK
23ms

在 GAE 日志中,我可以看到数据已正确处理。这是 Python 的响应代码:

self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(response)

【问题讨论】:

  • 移动应用程序是否托管在与后端不同的(子)域上?如果是这样 - see more on CORS here.
  • 是的,域不同,但我可以在服务器的日志中看到请求已成功计算并且响应已发送到我的移动客户端应用程序。 HTTP POST 的状态 200。

标签: python json angularjs google-app-engine mobile


【解决方案1】:

尝试添加

self.response.headers.add_header("Access-Control-Allow-Origin", "*")

之前

self.response.out.write(response)

如果可行,请将“*”替换为您的 Angular/移动应用的域。

Read more on Cross-origin resource sharing here.

【讨论】:

  • “如果可行,请将“*”替换为您的 Angular/移动应用程序的域”实际上移动客户端当前(仅测试)是从 localhost 提供的,但实际上它将是一个 cordova 移动应用程序。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-06
  • 1970-01-01
  • 2018-01-16
  • 2018-09-25
相关资源
最近更新 更多