How to login into Drupal 8 using the REST API?
'Content-Type': 'application/json' needs to be 'Content-Type': 'application/hal+json' in order for it to work.

I recommend you watch these video tutorials 

Learn Drupal 8 - REST API Part1  

Learn Drupal 8 - REST API Part2

The login is covered in part 2, but part 1 is very informative and part 2 will make more sense if you watch part 1. 

Although, the video tutorial uses the Google Chrome Postman add-on, your code needs to do the same. 


Have a header with the Content Type and Authorization values 

  GET http://{my-host}/user/testing



Your URL to POST, GET, or PATCH shouldn't be your user page, unless you want to work with the user fields. The URL needs to have the entity you are working with. 

For example: See the url's used in the video tuts.

You can even use Postman to generate your code

HTTP Generation

PATCH /node/1 HTTP/1.1
Host: forexample.com
Content-Type: application/hal+json
Authorization: Basic Q2FtaWxvOmNvY29saXNa
Cache-Control: no-cache // delete
Postman-Token: 3803eeac-0dc2-5c09-05e1-40d15d5b9820 // delete

{
"title": [
{
"value": "The title changed, WOOOHOOO!!!"
}
],
"type": [
{
"target_id": "article"
}
],
"_links": {
"type": {
"href": "http://forexample.com/rest/type/node/article"
}
}
}


PHPV1 generation 

&lt;?php

HttpRequest::methodRegister('PATCH');
$request = new HttpRequest();
$request-&gt;setUrl('http://forexample.com/node/1');
$request-&gt;setMethod(HttpRequest::HTTP_METH_PATCH);

$request-&gt;setHeaders(array(
  'postman-token' =&gt; '9656f5e8-13a5-0e2b-23cb-5ac03af59b5b', // remove this line
  'cache-control' =&gt; 'no-cache', // remove this line 
  'authorization' =&gt; 'Basic Q2FtaWxvOmNvY29saXNa',
  'content-type' =&gt; 'application/hal+json'
));

$request-&gt;setBody('{
"title": [
{
"value": "The title changed, WOOOHOOO!!!"
}
],
"type": [
{
"target_id": "article"
}
],
"_links": {
"type": {
"href": "http://forexample.com/rest/type/node/article"
}
}
}');

try {
  $response = $request-&gt;send();

  echo $response-&gt;getBody();
} catch (HttpException $ex) {
  echo $ex;
}


You can also generate for other languages like Python, jQuery, PHP Curl to name a few.