我目前正在研究一个Rails后端项目,我需要一些帮助来翻译这个curl命令。我们使用设计来允许用户登录,但我不确定如何将这个实现到AngularJS $ http请求中。
卷曲-v -H '内容类型:应用程序/ JSON' -H '接受:应用/ JSON的' -X POST http://localhost:3000/users -d
“{\” 用户\ “:{\” 电子邮件\ “:\” [email protected] \”,\ “密码\”:\ “密码\”}}”
我目前正在研究一个Rails后端项目,我需要一些帮助来翻译这个curl命令。我们使用设计来允许用户登录,但我不确定如何将这个实现到AngularJS $ http请求中。
卷曲-v -H '内容类型:应用程序/ JSON' -H '接受:应用/ JSON的' -X POST http://localhost:3000/users -d
“{\” 用户\ “:{\” 电子邮件\ “:\” [email protected] \”,\ “密码\”:\ “密码\”}}”
app.controller('LoginController', function($http){
var user = {"user":{"email":"[email protected]","password":"password"}};
$http.post('http://localhost:3000/users',user).then(function(result){
// success. do something
});
});
,你很可能想要发布帖子请求,为此,请将$http
服务注册到您的controller
或service
你想要发送请求并用你的用户数据调用post
到url,其中用户数据是一个json对象。