英文:
Angular $http post call passing data issue to GO backend
问题
我正在尝试访问用GO编写的后端,99%的情况下是没有问题的(问题不在那里)。
目前,我只创建了一个最简单的调用,它留在控制器中(将来会在服务中),用于注册新用户。尽管我硬编码了要传递的数据,但响应显示为403禁止访问。在PowerShell中显示403的原因是:
> RegistrationForm parse - email: , nick:
>
> 邮件验证失败 - 邮件为空
看起来我没有正确传递我的数据,因为邮件为空。请看一下我的代码:
$ctrl.fake_registerSubmit = function() {
$http({
url: 'http://localhost:3000/v1/sign_up',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
method: 'POST',
data: {
email: 'check@onet.pl',
nick: 'borysxoxo',
password: 'admin12312',
password_confirmation: 'admin12312'
}
})
.then(function successCall(response, post) {
console.log('user added');
}, function errorCall(respone) {
console.log('error callback');
console.log(respone);
})
};
这个屏幕截图展示了我正在尝试访问的API文档:
我做错了什么?还有其他传递数据的方法吗?
英文:
I am trying to get access to backend written in GO which in 99% is good (problem does not lay there).
For now I just created simplest call which stay in controller (it will be in service in future) to register new user. Although I hardcoded data which I am passing the response says 403 forbidden. In powerShell shows reason of 403:
> RegistrationForm parse - email: , nick:
>
> Validation failed for email - blank
It looks like I am not passing my data correctly because email is blank. Please take a look at my code:
$ctrl.fake_registerSubmit = function() {
$http({
url: 'http://localhost:3000/v1/sign_up',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
method: 'POST',
data: {
email: 'check@onet.pl',
nick: 'borysxoxo',
password: 'admin12312',
password_confirmation: 'admin12312'
}
})
.then(function successCall(response, post) {
console.log('user added');
}, function errorCall(respone) {
console.log('error callback');
console.log(respone);
})
};
This screenshot presents API documentation which I am trying to access:
What am I doing wrong? Is there other way to pass data?
答案1
得分: 0
你正在使用错误的Content-Type
发送一些JSON数据。
我看到有两个选项,要么在你的头部中将Content-Type
更改为:
'Content-type': 'application/json'
要么将你的有效载荷转换为:
data: "email=check@onet.pl&nick=borysxoxo&password=admin12312&password_confirmation=admin12312"
英文:
You are sending some json data with the wrong Content-Type
.
I see 2 options, either change Content-Type
in your header to:
'Content-type' : 'application/json'
or transform your payload to:
data: "email=check@onet.pl&nick=borysxoxo&password=admin12312&password_confirmation=admin12312"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论