Ich habe ein Problem, wenn ich AngularJS Daten zum Web API Endpunkt poste. Vom Client-Browser erhalte ich:Ajax Post zu Web API (405 Methode nicht erlaubt)
405 (Method Not Allowed)
Response for preflight has invalid HTTP status code 405
Ich habe zwei separate Projekte, die beide in localhost ausgeführt werden. Auf meiner Web-API habe ich EnableCors() auf Config gesetzt.
Wenn ich gesetzt Content-Typ des Headers an:
'Content-type': 'application/x-www-form-urlencoded; charset=utf-8'
Dann ist mein Web-API-Endpunkt traf es in der Lage zu. Mein Objektargument ist jedoch null. Könnte das XML-Format und nicht JSON sein? Wie gehe ich vor, um das zu lösen?
Client-Seite Code:
function signUp(data) {
$http({
method: 'POST',
url: 'http://localhost:15218/api/account/register',
data: JSON.stringify(data),
headers: {
'Content-type': 'application/json'
}
}).then(function successCallback(response) {
console.log(response);
}, function errorCallback(response) {
console.log(response);
});
}
}
Server Side Methode Signatur:
[HttpPost]
[Route("Register")]
public async Task<HttpResponseMessage> Register(UserCommand command)
Sie müssen cors auf der Serverseite aktivieren – Sajeetharan
Ja, ich habe und immer noch nicht funktioniert –
scheint es nicht angewendet – Sajeetharan