我第一次使用 POST Http Request 在 AngularJS 中提交表单,特别是该表单包含一个 keygen 元素,该元素生成如下所示的密钥:
<keygen id="spkac" name="spkac" challenge="randomchars" keytype="rsa" hidden>
spkac 元素到达服务器总是空的,而且我认为我没有以正确的方式将数据从表单传递到 POST,所以我的问题是:
- 如何将 spkac 设置为表单的参数部分?
- 这是将数据传递到AngularJS中的POST的正确方法吗?
编辑 表格:
<form name="signupForm" id="signupForm" method="POST" ng-submit="create()">
<input type="hidden" name="username" id="username" value="mtest">
<input type="text" placeholder="Account name" name="webid" ng-model="account.webid" ng-focus="isFocused" ng-blur="isFocused = false"><br>
<input type="text" placeholder="Full name" name="name" ng-model="account.name"><br>
<input type="text" placeholder="Email" name="email" ng-model="account.email"><br>
<input type="text" placeholder="Picture URL" name="pictureURL" ng-model="account.pictureURL"><br>
<keygen id="spkac" name="spkac" challenge="randomchars" keytype="rsa" hidden>
<input type="submit" id="submit" value="Submit">
</form>
编辑 HTTP 请求:
$scope.signupForm = {};
$scope.create = function () {
document.getElementById("submit").value = "Creating...";
var uri = "https://" + "...";
//setting spkac part of the form's parameters
$scope.account.spkac = document.getElementById("spkac");
$http({
method: 'POST',
url: uri,
data: $.param($scope.account),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/x-x509-user-cert'
},
withCredentials: true
}).
success(function(data, status, headers) {
if (status == 200 || status == 201) {
//Account created
}
}).
编辑 2