Hello
I have a asp.net core web api, that I calling from Xamarin. The normal CRUD methods work fine. I am trying however to add a method to the web api to send a list of objects. However I keep getting an error stating (see below). Ive also included my client side code and the method on the web api. I have googled and googled and googled, I cannot figure out what I am doing wrong.
My client side code looks like:
public async Task<bool> DiffSyncAsync(string jsonUpate)
{
var httpClient = new HttpClient();
HttpContent content = new StringContent(jsonUpate);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var result = await httpClient.PostAsync(WebServiceURL + "DiffertialSync", content);
return result.IsSuccessStatusCode;
}
My api method looks like:
[Route("api/vehicles/DiffertialSync")]
public async Task<IActionResult> PostVehicles([FromBody] List<Vehicle> vehicles)
{
if (vehicles == null || _context.Vehicle == null)
{
return NotFound();
}
try
{
//List<Vehicle> Vehicles = JsonConvert.DeserializeObject<List<Vehicle>>(vehiclesJson);
//if (Vehicles != null)
//{
// foreach (var vehicle in Vehicles)
// {
// _context.Entry(vehicle).State = EntityState.Modified;
// await _context.SaveChangesAsync();
// }
// return Ok(true);
//}
return Ok(false);
}
catch (Exception)
{
throw;
}
}
statusCode: 405, ReasonPhrase: 'Method Not Allowed', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Date: Mon, 13 Jun 2022 14:00:48 GMT
Server: Microsoft-IIS/10.0
Set-Cookie: ARRAffinity=8a89f47e19228123334b19b17c93837ee63c5f8af4981359f4abaa40ce6cbea9;Path=/;HttpOnly;Secure;Domain=myautoapi20220609112603.azurewebsites.net
Set-Cookie: ARRAffinitySameSite=8a89f47e19228123334b19b17c93837ee63c5f8af4981359f4abaa40ce6cbea9;Path=/;HttpOnly;SameSite=None;Secure;Domain=myautoapi20220609112603.azurewebsites.net
X-Android-Received-Millis: 1655128849680
X-Android-Response-Source: NETWORK 405
X-Android-Selected-Protocol: http/1.1