0

я новичок в веб-Апи и реализации авторизации и аутентификации, но получает некоторую ошибку, как я упоминал ниже:unsupported_grant_type в Web Api 2

Я получаю эту ошибку при получении маркера из WebAPI

{"readyState":4,"responseText":"{\"error\":\"unsupported_grant_type\"}","responseJSON":{"error":"unsupported_grant_type"},"status":400,"statusText":"Bad Request"} 

Этот мой JQuery код, чтобы сделать запрос для маркеров

$(document).ready(function() { 
    $("#login").click(function() { 
     debugger; 
     var details = "{'grant_type':'password', 'username': '" + $("#UserName").val() + "', 'password': '" + $("#Password").val() + "' }"; 
     console.log(details); 
     $.ajax({ 
      type: "POST", 
      contentType: "application/x-www-form-urlencoded", 
      data: details, 
      url: "http://localhost:59926/token", 
      success: function (data) { console.log(JSON.stringify(data)); }, 
      error: function (data) { console.log(JSON.stringify(data)); } 
     }); 
    }); 
+0

'contentType' должно быть' application/json'. – Venky

ответ

0

contentType неправильно. Это должно быть application/json

$(document).ready(function() { 
    $("#login").click(function() { 
     debugger; 
     var details = "{'grant_type':'password', 'username': '" + $("#UserName").val() + "', 'password': '" + $("#Password").val() + "' }"; 
     console.log(details); 
     $.ajax({ 
      type: "POST", 
      contentType: "application/json", 
      data: details, 
      url: "http://localhost:59926/token", 
      success: function (data) { console.log(JSON.stringify(data)); }, 
      error: function (data) { console.log(JSON.stringify(data)); } 
     }); 
    }); 
+0

, но я получаю ту же ошибку: '{" readyState ": 4," responseText ":" {\ "error \": \ "unsupported_grant_type \"} "," responseJSON ": {" error ":" unsupported_grant_type "} , «status»: 400, «statusText»: «Bad Request»} ' –

+0

, также выпишите свой код webapi и как вы пытаетесь реализовать аутентификацию – Venky