【发布时间】:2014-05-06 06:01:32
【问题描述】:
使用 AngularJS + Express 我有以下代码将我的请求代理到远程服务:
app.get('/api.json', function (req, res) {
req.pipe(request("http://test-api.com/api.json")).pipe(res);
});
app.post('/api.json', function (req, res) {
req.pipe(request.post("http://test-api.com/api.json")).pipe(res);
});
所有 GET 请求都可以正常工作,但是 POST 请求在我的浏览器中等待处理。
这是我发帖的方式:
$http({
method: 'POST',
url: '/api.json',
data: $.param({
"title": not.title,
"desc": not.description
}), // pass in data as strings
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).success(function () {alert("Success");});
怎么了?
编辑: 这是控制台上看到的请求:
我应该检查什么以提供更多信息?
【问题讨论】:
-
URL 不匹配:客户端 POST 到
/notifications.json,而服务器代码处理/api.json -
只是一个错字... eidted
-
如果它处于挂起状态,则指向
request.post的管道不会返回任何内容或永远无法到达。如果流永远不会恢复,则响应将永远不会写入res -
感谢您的回复,但是当我从客户端(通过表单)直接 POST 到 API 时,我会立即收到回复
-
有什么新想法吗?我迷路了:(
标签: node.js angularjs express proxy request