다음 튜토리얼을 따라 내 푸른 하늘의 백엔드를 설정했습니다.C# Azure/Postman - 405 POST에서 허용되지 않는 메소드 오류
https://adrianhall.github.io/develop-mobile-apps-with-csharp-and-azure/chapter2/custom/
것은 그때 처음으로 우체부를 설치하고 설정합니다
http://apptest.azurewebsites.net/.auth/login/custom
{ "이름": "아드리안", "비밀번호": "supersecret"}
Json (application/json)
그러나이 오류가 계속 발생합니다.
405 방법은
{
"Message": "The requested resource does not support http method 'GET'."
}
백엔드 코드 허용하지 :
using System;
using System.IdentityModel.Tokens;
using System.Linq;
using System.Security.Claims;
using System.Web.Http;
using Newtonsoft.Json;
using AppTestService.Models;
using AppTestService.DataObjects;
using Microsoft.Azure.Mobile.Server.Login;
namespace AppTestService.Controllers
{
[Route(".auth/login/custom")]
public class CustomAuthController : ApiController
{
private AppTestContext db;
private string signingKey, audience, issuer;
public CustomAuthController()
{
db = new AppTestContext();
signingKey = Environment.GetEnvironmentVariable("WEBSITE_AUTH_SIGNING_KEY");
var website = Environment.GetEnvironmentVariable("WEBSITE_HOSTNAME");
audience = $"https://{website}/";
issuer = $"https://{website}/";
}
[System.Web.Http.HttpPost]
public IHttpActionResult Post([FromBody] User body)
{
if (body == null || body.Username == null || body.Password == null ||
body.Username.Length == 0 || body.Password.Length == 0)
{
return BadRequest();
}
if (!IsValidUser(body))
{
return Unauthorized();
}
var claims = new Claim[]
{
new Claim(JwtRegisteredClaimNames.Sub, body.Username)
};
JwtSecurityToken token = AppServiceLoginHandler.CreateToken(
claims, signingKey, audience, issuer, TimeSpan.FromDays(30));
return Ok(new LoginResult()
{
AuthenticationToken = token.RawData,
User = new LoginResultUser { UserId = body.Username }
});
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
private bool IsValidUser(User user)
{
return db.Users.Count(u => u.Username.Equals(user.Username) && u.Password.Equals(user.Password)) > 0;
}
}
public class LoginResult
{
[JsonProperty(PropertyName = "authenticationToken")]
public string AuthenticationToken { get; set; }
[JsonProperty(PropertyName = "user")]
public LoginResultUser User { get; set; }
}
public class LoginResultUser
{
[JsonProperty(PropertyName = "userId")]
public string UserId { get; set; }
}
}
난 함수의 상단에 [System.Web.Http.HttpGet] 추가하는 경우
, 그럼 난 다른 오류가 발생합니다. :415 지원되지 않는 미디어 유형
{
"Message": "The request contains an entity body but no Content-Type header. The inferred media type 'application/octet-stream' is not supported for this resource."
}
이러한 헤더입니다
Allow →POST
Content-Length →72
Content-Type →application/json; charset=utf-8
Date →Sat, 28 Jan 2017 22:08:48 GMT
Server →Microsoft-IIS/8.0
X-Powered-By →ASP.NET
당신이 당신의 요청에 콘텐츠 형식을 전달하는이 경우 통화에서
:이 경우에는 다음과 같이
푸른 로그가 보인다? –
GET과 관련된 두 가지 오류가 있습니다. Content-Type = "application/json"으로 POST 요청을 보내면 어떤 오류가 발생합니까? –