[英]How to insert data in eXist-db by $http in AngularJS through the REST API?
我是AngularJS的新手。 现在,我尝试通过AngularJS的REST API在eXist-db数据库中插入xml数据。 我的文档包含以下内容:
<students>
<student>
<id>1</id>
<name>one</name>
</student>
<student>
<id>2</id>
<name>two</name>
</student>
</students>
我想在两个学生之后插入一个学生,如下所示:
<students>
<student>
<id>1</id>
<name>one</name>
</student>
<student>
<id>2</id>
<name>two</name>
</student>
<student>
<id>3</id>
<name>three</name>
</student>
</students>
我在Postman客户端中使用POST请求进行测试,其工作原理如下图: URL为http:// localhost:9999 / exist / rest / db / data / studentdata.xml,Content-Type为application / x-www-form-urlencoded
之后,我尝试像这样在AngularJS中使用$ http:
$scope.saveData = function(){
var req={
method:'POST',
url:'http://localhost:9999/exist/rest/db/data/studentdata.xml',
header:{
'Authorization':'Basic YWRtaW46MTIzNDU2',
'Content-Type':'application/x-www-form-urlencoded'
},
data:{_query:'update insert <student><id>3</id><name>three</name></student> into //students'}
};
$http(req).then(function(response){
alert("save finish");
});
}//end function
但是它有错误400(解析请求时出现SAX异常:序言中不允许内容)。
你能告诉我是什么问题吗? 我该如何解决这个错误? 非常感谢你。
现在,我可以使用此代码运行它了(没有任何错误)。
var promise = $http({
method:'POST',
url: 'http://localhost:9999/exist/rest/db/data/studentdata.xml',
headers: {'Authorization': 'Basic YWRtaW46MTIzNDU2','Content-Type':'application/x-www-form-urlencoded'},
data:'_query=update insert <student><id>3</id><name>three</name></student> into //students'
});
promise.success(function(data){
alert("successful");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.