C
C#9mo ago
Gecko

405 Method Not Allowed

I am receiving a 405 error, with no other relevant log messages. Any ideas what's happening? Accessor
public async Task<Response<int>> AddPermit<T>(T permit) where T : PermitDetails
{
var response = await _permitAccessor.AddPermit<T>(permit);
return response;
}
public async Task<Response<int>> AddPermit<T>(T permit) where T : PermitDetails
{
var response = await _permitAccessor.AddPermit<T>(permit);
return response;
}
IPermitClient
Task<Response<int>> AddPermit<T>(T permit) where T : PermitDetails;
Task<Response<int>> AddPermit<T>(T permit) where T : PermitDetails;
PermitClient
c#
public async Task<Response<int>> AddPermit<T>(T permit) where T : PermitDetails
{
var result = await _http.PostAsJsonAsync("api/permit", permit);
return await result.Content.ReadFromJsonAsync<Response<int>>();
}
c#
public async Task<Response<int>> AddPermit<T>(T permit) where T : PermitDetails
{
var result = await _http.PostAsJsonAsync("api/permit", permit);
return await result.Content.ReadFromJsonAsync<Response<int>>();
}
AddPermit (Frontend code where the PermitClient is called with data)
c#
PermitClient.AddPermit(Constants.MockPermits.PermitList[0]);
c#
PermitClient.AddPermit(Constants.MockPermits.PermitList[0]);
MockPermits.PermitList
c#
public static PermitDetails[] PermitList = {
new PermitDetails()
{
PermitType = "Mechanical Amusement",
BusinessDetails = MockBusiness.MockBusinessExample,
LocationDetails = MockLocation.MockLocationExample,
Status = "Approved",
StartDate = new DateTime(2022, 02, 27),
EndDate = new DateTime(2023, 02, 27),
Signature = Array.Empty<byte>(),
},
}
c#
public static PermitDetails[] PermitList = {
new PermitDetails()
{
PermitType = "Mechanical Amusement",
BusinessDetails = MockBusiness.MockBusinessExample,
LocationDetails = MockLocation.MockLocationExample,
Status = "Approved",
StartDate = new DateTime(2022, 02, 27),
EndDate = new DateTime(2023, 02, 27),
Signature = Array.Empty<byte>(),
},
}
Didn't include the controller, because this error happens before the controller is even reached
4 Replies
Not Mark
Not Mark9mo ago
From the error it sounds like whatever endpoint you're trying to hit doesn't support whatever http method you're sending.
_http.PostAsJsonAsync("api/permit", permit);
_http.PostAsJsonAsync("api/permit", permit);
This suggests you're sending a POST, but does that endpoint actually support a POST? Or if it does, does the PostAsJsonAsync method actually send it as a POST?
Pobiega
Pobiega9mo ago
show the controller the problem is most likely that you didn't give it the right [HttpX] attribute, thus there is no route matching your request so its not entering the action you want it to, because there is no matching route
Gecko
Gecko9mo ago
c#

[HttpPost, Authorize]
public async Task<ActionResult<Response<int>>> AddPermit<T>(T permit) where T : PermitDetails
{
var result = await _permitManager.AddPermit<T>(permit);
if (result.Success)
{
return Ok(result);
}
else
{
return new ConflictObjectResult(result);
}

}
c#

[HttpPost, Authorize]
public async Task<ActionResult<Response<int>>> AddPermit<T>(T permit) where T : PermitDetails
{
var result = await _permitManager.AddPermit<T>(permit);
if (result.Success)
{
return Ok(result);
}
else
{
return new ConflictObjectResult(result);
}

}
Pobiega
Pobiega9mo ago
and the request mantches that route? ie, has the route inherited from the controller and is a POST request?
Want results from more Discord servers?
Add your server