0

I am using Drupal 8.6.4

http://example.org/user/login?_format=json

When I try to submit a post request, it returns HTML page instead of JSON response.

I am sending headers:

  Content-Type: application/json

and data as:

 { "name": "admin" , "pass": "admin" }

What am I missing?

  • how did you make the post request, you sent the body as Body Raw, i have tested it with this and it works it return { "current_user": { "uid": "1", "roles": [ "authenticated", "administrator", ], "name": "Admin" }, "csrf_token": "e9dWDT505MjVlxhJfmH-CYFoeBAodyzASGUB98B8Fuk", "logout_token": "8ZAv1Pyd0YBEsBV4maTgeLN6rkuOt70Pa3pSMEUvpkA" } – berramou Feb 16 at 19:05
  • Hi @berramou , yes I am sending it as raw , but I am getting logged in HTML page. The return value is not json. I am using Postman for testing. – InspiredCoder Feb 16 at 21:10
  • make sure that type of raw is JSON (application/json) – berramou Feb 16 at 22:27
  • Yes, I have set it Content-Type: application/json . But I am not sure why it is giving me HTML. It should have worked, but I am still unable to fix it. – InspiredCoder Feb 16 at 22:31
  • 2
    I have figured it. Turns out that Redirect after login was redirecting to the given URL which resulted in HTML output. I have disabled that and now I am getting proper JSON response. – InspiredCoder Feb 17 at 0:37
1

It turned out that the Redirect after login module was redirecting to the given URL, which resulted in HTML being output. I have disabled that and now I am getting the proper JSON response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.