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.
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
}
});
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
}
});
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
The RESTful Web Services API is new in Drupal 8. For each REST resource, you can specify the supported verbs, and for each verb, you can specify the serialization formats & authentication mechanisms.
OAuth 2.0. OAuth (specifically, OAuth 2.0) is considered a gold standard when it comes to REST API authentication, especially in enterprise scenarios involving sophisticated web and mobile applications.
You have to enable application/x-www-form-urlencoded content type of your service endpoint.
Do as follows: Services -> Edit Resources -> select tab "Server" -> enable "application/x-www-form-urlencoded" and that's it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With