In my PayPalService.cs file, I have a public method in the class that calls an Azure HTTP triggered method in PayPalFunctions.cs file that keeps failing due to an error: "Method not Allowed".
This is the calling function:
public async Task<OrderResponse> CreateOrderAsync(PaymentOrderRequest request)
{
var response = await _httpClient.PostAsJsonAsync("api/CreateOrder", request).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
return await response.Content.ReadFromJsonAsync<OrderResponse>();
}
Trigger function is defined as:
[Function("CreateOrder")]
public async Task<HttpResponseData> CreateOrderAsync(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestData req)
{
_logger.LogInformation("Create Order");
// Read request body
string requestBody = await new StreamReader(req.Body).ReadToEndAsync().ConfigureAwait(false);
var orderRequest = JsonConvert.DeserializeObject<PaymentOrderRequest>(requestBody);
// ... etc
}
So the PostAsJsonAsync call to the CreateOrder function is being rejected due to:
Response status code does not indicate success: 405 (Method Not Allowed) "Method: POST, RequestUri: 'http://localhost:5047/api/CreateOrder', Version: 1.1, Content: System.Net.Http.Json.JsonContent, Headers: { Transfer-Encoding: chunked Content-Type: application/json; charset=utf-8 }"
All searches in Google indicate the PostAsJsonAsync call to the function is failing because the httptrigger method does not include "post". But it DOES.
Any ideas as to what is happening?
Further background - the call was originally being made from a WebAssembly page to the SSR app. I am trying to make it all work in SSR only, for security reasons.
postrequest? Looking at your error I would assume that the problem is revolving around the fact that you are using a post request, not that it may be missing somewhere.