【发布时间】:2016-04-24 02:19:37
【问题描述】:
我正在开发一个新的 Angular 客户端,它应该与我的 Node/Express 服务器进行通信。我目前正在尝试开发第一步,即登录。这应该是一个 http json 帖子。事实证明,每次我从客户端执行该帖子到服务器时,Node/Express 服务器都找不到我的路径的路由。
在服务器的控制台日志中,对于我的 post json 请求,我发现以下堆栈跟踪:
OPTIONS /api/auth/facebook/mobile 404 274.092 ms - 1980
节点/Express端:
我的路线
app.post('/api/auth/facebook/mobile', authenticationHandler.handleFacebookMobileLoginRequest);
定义了 json 的正文解析器:
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
在 Angular 客户端,我这样做:
http({
method: 'POST',
url: 'http://192.168.1.101:3000/api/auth/facebook/mobile',
headers: { 'Content-Type': 'application/json; charset=UTF-8;' },
data: {fbToken: authResponse.accessToken}
})
.then(function (response) {
...
有趣的事实:
-
当我从 Java 应用或 Android 原生应用调用时,相同的路由可以正常工作,例如
final JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, SERVER_URL + "/api/auth/facebook/mobile", params, jsonRequestListener, errorListener);
1234563此外,我在 Angular 客户端遇到了一个问题,没有分别处理答案,答案永远不会出现在
.then(... 函数中。这同样适用于其他客户端。
有人有想法、线索还是我应该打电话给 Strange 博士?
【问题讨论】:
标签: angularjs json node.js http post