通过 Rest 服务器登录 Drupal [英] Drupal login via Rest server
问题描述
我正在开发一个网站,该网站将外部 Drupal 用于文章和页面.目的是仅使用 html/css/js 显示网站中的文章.
I'm developing a website who uses an external Drupal for the articles and pages. The purpose is to show the articles in a website using just html/css/js.
我在 drupal 后端添加了一个 Rest Server 模块,所以我可以执行 http 请求来检索文章.现在从 drupal 后端工作中检索文章(见下面的代码).Restdrupal 是我的站点的名称,restendpoint 是 Rest 服务器端点的名称(Captian Obvious)
I've added an Rest Server module to the drupal back-end so I can do http requests for retreiving the articles. Now retreiving the articles from the drupal back-end works (see code below). Restdrupal is the name of my site and restendpoint is the name of the Rest server's endpoint (Captian Obvious)
$.ajax({
url : "http://127.0.0.1/restdrupal/restendpoint/node.json",
dataType : 'json',
success : function(data) {
//further code
}
});
现在我希望我的客户能够添加一些文章,所以我需要先登录.我已经在互联网上搜索了好几天并尝试了上百万种方法,但没有任何效果对我有用.我最近尝试过的(使用 jQuery)是这样的:
Now I want my customer to be able to add some articles, so I need to login first. I've been searching the internet for days now and tried a million things but nothing worked for me. The latest thing i've tried (with jQuery) was this :
$.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...
I've also changed the PUT into POST...
我得到的回应是(不管我做什么)是一样的:
The response i'm getting is (no mather what I do) the same :
406 Not Acceptable: Unsupported request content type application/x-www-form-urlencoded
有人可以帮我吗?亲切的问候,欧洲
Could please somebody help me? Kind regards, Ceetn
推荐答案
您必须启用服务端点的 application/x-www-form-urlencoded 内容类型.
You have to enable application/x-www-form-urlencoded content type of your service endpoint.
执行以下操作:服务 -> 编辑资源 -> 选择选项卡服务器"-> 启用应用程序/x-www-form-urlencoded",就是这样
Do as follows: Services -> Edit Resources -> select tab "Server" -> enable "application/x-www-form-urlencoded" and that's it
这篇关于通过 Rest 服务器登录 Drupal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!