我目前正在开发一个带有Rails后端的项目,我需要一些帮助来翻译这个curl命令。我们正在使用设计允许用户登录,但我不确定如何将其实现为AngularJS $ http请求。
curl -v -H'Content-Type:application / json'-H'Eccept:application / json'-X POST http://localhost:3000/users -d
“{\” 用户\ “:{\” 电子邮件\ “:\” user@example.com \”,\ “密码\”:\ “密码\”}}”
答案 0 :(得分:1)
答案 1 :(得分:1)
app.controller('LoginController', function($http){
var user = {"user":{"email":"user@example.com","password":"password"}};
$http.post('http://localhost:3000/users',user).then(function(result){
// success. do something
});
});
所以,你几乎想发一个帖子请求。为此,请将$http
服务注入您要发出请求的controller
或service
,并使用您的用户数据调用post
url,其中用户数据为json对象