API endpoint not working for POST request

We have developed an API endpoint and it is not working on the production site, this endpoint works perfectly on local host or even using tools like NGROK with GET and POST request.

We have already configured the code so it can accept http and https requests, however we are still getting the error in production. Something curious is that using Postman for example, if we do a GET request, it works perfectly fine, however with a POST request, we get a http "404 - File or directory not found" error, and there is where we are right now and we are not able to move forward.

The body that we sent to the endpoint is perfectly fine as well, this is the code that receive the call of the API from Postman:

[HttpPost]
public ActionResult PaymentNotification(PaymentSession notification)
{
   System.Diagnostics.Debug.WriteLine("PaymentNotification endpoint hit");
   // Verifica si el cuerpo de la solicitud está vacío o es inválido
   if (notification == null || notification.status == null || string.IsNullOrEmpty(notification.signature))
   {
       var jsonResult = new JsonResult
       {
           Data = new { message = "Los datos de la solicitud son inválidos o incompletos." },
           JsonRequestBehavior = JsonRequestBehavior.AllowGet
       };
       Response.StatusCode = 400; // Código 400 (Bad Request)
       return jsonResult;
   }

   string secretKey = "Hide for security purposes"; // La clave que usas para firmar
   string calculatedSignature = GenerateSignature(notification, secretKey);

   // Verifica si la firma no coincide
   if (calculatedSignature != notification.signature)
   {
       var jsonResult = new JsonResult
       {
           Data = new { message = "Firma inválida." },
           JsonRequestBehavior = JsonRequestBehavior.AllowGet
       };
       Response.StatusCode = 401; // Código de estado HTTP 401 (No autorizado)
       return jsonResult;
   }

   // Busca la sesión de pago
   if (!ExisteRegistro(notification.requestId, notification.reference))
   {
       var jsonResult = new JsonResult
       {
           Data = new { message = "Sesión no encontrada." },
           JsonRequestBehavior = JsonRequestBehavior.AllowGet
       };
       Response.StatusCode = 404; // Código de estado HTTP 404 (Not Found)
       return jsonResult;
   }

   // Guarda la sesión de pago actualizada
   PayUResponse(notification.requestId);

   // Responde con código 200 (OK) y mensaje de éxito
   var successResult = new JsonResult
   {
       Data = new { message = "Notificación procesada correctamente." },
       JsonRequestBehavior = JsonRequestBehavior.AllowGet
   };
   Response.StatusCode = 200; // Código de estado HTTP 200 (OK)
   return successResult;
}

We have tried everything but we can still not get it to work, we suspect that it might be the configuration from IIS on the server the domain is hosted, if you guys have any idea of what it could be please let me know or any ideas on the settings of IIS.

The code is already set up to receive http and https request's as well as the IIS server.

The end point works perfectly fine on localhost or even using NGROK , and it works for POST and GET.

With the production domain it does not work, the URL is totally fine and the GET request allow me to get some data that we have to make sure that it works but on POST request we receive error 404 - File or directory not found.

Upvotes: 0

Views: 57

Answers (1)

John Gualteros
John Gualteros

Reputation: 3

I'm not a c# expert, but you are extending BaseController in this controller.

  • Other possible issue is that you have one prefix for requests?
  • Are you sure all imports are correct? Is the request mapping correctly configured? Maybe it cannot be started with "/".

I will share one example of my recent project, so you can compare it in order to see the differences: code github image example

Upvotes: 0

Related Questions