POST request not working when processed from frontend | Community
Skip to main content
January 31, 2023

POST request not working when processed from frontend

  • January 31, 2023
  • 5 replies
  • 1826 views

Hello there, I'm facing a strange issue when I try to make a POST request from my frontend(I'm currently using React, but i'm doing these requests from localhost:4502). I know for sure that the servlet it's working because when I do a POST request from Postman works correctly. When I do it from the frontend it gives me 403(Forbidden). Why it has different behaviour when I do the legit same things?
Info about servlet: 
Servlet temporary binded to /bin/vendorname/utils

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

5 replies

Nitin_laad
Community Advisor
Community Advisor
January 31, 2023

You should check CORS configuration, check the allowed method types,

Allowed Methods

  • "supportedmethods"
  • List of method parameters indicating which HTTP methods can be used when making the actual request.

Understand Cross-Origin Resource Sharing (CORS) with AEM | Adobe Experience Manager

January 31, 2023

Thank you for your answer @nitin_laad 
Currently my cors settings are:
allowedorigins: "http://localhost:3000"
allowedmethods(supportedmethods): ["GET", "POST", "HEAD"]

supportedheaders: [ "Authorization""Origin", "Accept", "X-Requested-With", "Content-Type", "Access-Control-Request-Method""Access-Control-Request-Headers"]

Manu_Mathew_
Community Advisor
Community Advisor
February 1, 2023

@lezzowski1 You may have to remove the POST value from the filter in  "Apache Sling Referrer Filter" and "Adobe Granite CSRF Filter" configuration - http://localhost:4502/system/console/configMgr

SantoshSai
Community Advisor
Community Advisor
February 1, 2023
arunpatidar
Community Advisor
Community Advisor
February 1, 2023

hi,

You need to pass the authentication(credentials with post request) since it is Author.

Try in publish instance, it should work.

Arun Patidar
February 1, 2023

Good news, my servlet is currently working while binded on path but if I try to bind it on a component with SlingServletResourceTypes my request status code is 200 but it does nothing. It just says Content Modified or something similar instead of my json. Any thoughts?

arunpatidar
Community Advisor
Community Advisor
February 2, 2023

Can you share, how did you registered the servlet.

Better to use selector to avoid resolution of default post servlet.

Arun Patidar
February 3, 2023

Seems like the problem was this one: I wasn't setting "methods = "POST" " in the decorator. I'm kinda shocked because why should the servlet work as intended when binded to path (and I didn't explicitly set "methods = POST") but not when binded to component? It's totally crazy