Drupal通过Rest服务器登录

我正在开发一个使用外部Drupal来处理文章和页面的网站。 目的是仅使用html / css / js在网站中显示文章。

我已经向drupal后端添加了一个Rest Server模块,因此我可以执行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 } }); 

现在我希望我的客户能够添加一些文章,所以我需要先登录。 我已经在互联网上搜索了几天,尝试了一百万件事,但对我来说没有任何作用。 我尝试过的最新function(使用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

您必须启用服务端点的application / x-www-form-urlencoded内容类型。

执行如下操作:服务 – >编辑资源 – >选择选项卡“服务器” – >启用“application / x-www-form-urlencoded”,就是这样

自己找到了解决方案。 对于那些感兴趣的人:

 $.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 } }); 

可能需要启用该解析器类型?

检查此链接。 也许它会帮助你得到一些想法https://drupal.stackexchange.com/questions/3207/simple-rest-request-to-create-nodes