0

i Anfänger bin in Web Api und Autorisierung und Authentifizierung der Umsetzung aber einige Fehler bekommen, wie ich weiter unten erwähnt:unsupported_grant_type in Web Api 2

Ich erhalte diesen Fehler während Token von WebAPI

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

Diese Code ist meine jQuery Anfrage für Token

$(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' sollte' application/json' sein. – Venky

Antwort

0

contentType falsch zu machen ist. Es sollte application/json sein

$(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

aber ich bekomme den gleichen Fehler: '{" readyState ": 4," responseText ":" {\ "error \": \ "nicht unterstützter_grant_type \"} "," responseJSON ": {" error ":" unsupported_grant_type "} , "status": 400, "statusText": "Ungültige Anfrage"} ' –

+0

posten Sie auch Ihren Webapi-Code und wie Sie versuchen, die Authentifizierung zu implementieren – Venky