我正在开发一个使用外部Drupal来处理文章和页面的网站。 目的是仅使用html / css / js在网站上显示文章。
我已经将一个Rest服务器模块添加到了drupal后端,因此我可以执行http请求来检索文章。现在从drupal后端工作中检索文章(参见下面的代码)。 Restdrupal是我的站点的名称,restendpoint是Rest服务器端点的名称(Captian Obvious)
$.ajax({
url : "http://127.0.0.1/restdrupal/restendpoint/node.json",
dataType : 'json',
success : function(data) {
//further code
}
});
现在我希望我的客户能够添加一些文章,所以我需要先登录。 我已经在互联网上搜索了几天,尝试了一百万件事,但对我来说没有任何作用。我尝试过的最新事物(使用jQuery)是这样的:
$.ajax({
url : "http://127.0.0.1/restdrupal/restendpoint/user/login",
dataType:'application/json',
type : 'PUT',
data : 'Name=myusername&Pass=mypassword',
success : function(data) {
//further code
},
error:function(data){
//Error handling
}
});
我也把PUT变成了POST ......
我得到的回答是(不管我做什么)同样的事情:
406 Not Acceptable: Unsupported request content type application/x-www-form-urlencoded
可以请有人帮助我吗? 亲切的问候, Ceetn
答案 0 :(得分:24)
您必须启用服务端点的application / x-www-form-urlencoded内容类型。
执行以下操作:服务 - >编辑资源 - >选择标签“服务器” - >启用“application / x-www-form-urlencoded”,就是这样
答案 1 :(得分:2)
自己找到解决方案。对于那些感兴趣的人:
$.ajax({
url : "http://127.0.0.1/restdrupal/restpoint/user/login.json",
type : 'post',
data : 'username=' + encodeURIComponent(username) + '&password=' + encodeURIComponent(password),
dataType : 'json',
error : function(data) {
//error code
},
success : function(data) {
//success code
}
});
答案 2 :(得分:1)
可能需要启用该解析器类型吗?
检查此链接。也许它会帮助你得到一些想法https://drupal.stackexchange.com/questions/3207/simple-rest-request-to-create-nodes