React post method 404 to Public Url - reactjs

I have created a React application, i am trying to secure a param which is sent as a initial query parameter in url, is there a way for the first public url request with post method?
http://localhost:3000/ GET i can download content
http://localhost:3000/ POST i got 404 error
(i am trying to find a way to get content like GET method request)
I hope my question is clear enough, i am looking forward to hearing your ideas,

Related

AXIOS post request - missing url param

I set a react webpage that has is structured as follow:
MAIN PAGE www.localhost:3000.com,
OTHER PAGES www.localhost:3000.com/services, www.localhost:3000.com/about, www.localhost:3000.com/contactMe.
I'm using axios from www.localhost:3000.com/contactMe to perform a post for a contact form that will send data thru my backend/nodemailer.
Using Postman to verify the post status, the post method is NOT working from www.localhost:3000.com/contactMe/api/contact and it works correctly for localhost:3000/api/contact and localhost:5000/api/contact.
How could I fix this Request failed with status code 404 from www.localhost:3000.com/contactMe/api/contact?
HOST: localhost:3000
SERVER: app.use('/api,...)
CONTROLLER: pouter.post('/contact',...)
One solution could be to just use the base URL and send the POST request to www.localhost:3000.com/api/contact from any page.
So even if the user is on www.localhost:3000.com/contactMe, it still sends the request to www.localhost:3000.com/api/contact.
A quick way to get it is using window.location.hostname.
Another way is just putting a / in the beginning of the URL you're putting in your POST request axios.post('/api/contact', ...) and it should send it directly to ${baseURL}/api/contact from any page

405 HTTP error after being redirected from payment gateway

we are using Vercel for making development fast .
in our react app , after payment page when payment redirect to our given url it gives 405 http error, how can we handle this?
I finally found the problem , it is coming from PayTabs's side
followings are the logic they are handling wrong:
when nothing is received from callback url , they should not redirect us with given redirect url
when we are giving an invalid callback url it make a GET request to given redirect url
when we are giving an valid callback url which returns 200 to them it make a POST request to given redirect url which is not supported by browser.
This error happens when your page does not use next js serverside rendering. I had same issue but solved it by converting the page from a static page to a server rendered page using getServerSideProps

Modify HTTP Method for Request in Browser

i am Learning Python and at the moment i am experimenting with the request Module.
What i did so far:
This is the API Documentation for the Endpoint i used:
https://trackapi.nutritionix.com/docs/#/default/post_v2_natural_exercise
And this is the associated Python Code:
EXERCISES_ENDPOINT = "https://trackapi.nutritionix.com/v2/natural/exercise"
header = {
"x-app-id": APP_ID,
"x-app-key": API_KEY
}
body = {
"query": "Ran 2 miles and walked for 3Km."
}
response = requests.post(url=EXERCISES_ENDPOINT, headers=header, json=body)
The corresponding http Request URL should be:
https://trackapi.nutritionix.com/v2/natural/exercise?Ran%202%20miles%20and%20walked%20%20for%203Km.
My Problem is as follows:
In Python the code ist working perfectly fine and my response is as expected
If i use Postman, this works fine too, because in both -Python and Postman - i can specify my Request as a POST Method
But if i use the URL in my MS Edge Browser (and Chrome too) i get an Error: Cannot GET /v2/natural/exercise
The Header information are ok, because i told the Browser them per "ModHeader" Extension.
But why is my Browser doing a GET and not a POST and how can i change this with the developemant tools from MS Edge Browser.
Important for my learning is to know why the Browser do a GET??
Is the Browser only able to do GET in generel and the other Methods (POST, PUT, DELETE) are not possible in this way. But that makes no sense for me :)
Thanks a lot in advance
But why is my Browser doing a GET and not a POST
Presumably because you are trying the address into the address bar of the browser.
That is designed to make a GET request because there is nothing in the UI designed to collect any of the data needed to make another request type.
The usual way to make a POST request would be to provide a user interface for it in the form of an HTML <form>.

My API laravel doesn't work when it run on my reactjs

I got a problem, my API laravel doesn't work when it run on my reactjs. When I check, i got failed response data. But,it work fine in postman. Here's my code
This is in reactjs :
This code in ReactJs
and this is in laravel API :
this code in laravel API
i use axios to get response from my API, and i have already set my cors before in my Laravel, just one function can't get response.
here the respons :
response in postman
response in console log react when use chrome
response in network google chrome
I already try to set up cors again and try to change method put to get and put to post, and still doesnt work. I don't know where the problem is.
Maybe you can try to connect with jquery or javascript XMLHttpRequest to make sure where is the problem

TYPO3: 404 not rewriting URL

So Im having quite trouble to get speaking URLs in TYPO3. I managed to make them work with this 2 lines in localconf.php
$TYPO3_CONF_VARS["FE"]["pageNotFound_handling"] = 'http://www.mysite.com/';
$TYPO3_CONF_VARS["FE"]["pageNotFound_handling_statheader"] = 'HTTP/1.1 404 Not Found';
But the problem is that if I type a inexisting page, it even though it will direct me to the homepage, it wont rewrite the URL in the browser. Is there something that can be done about this?
It's the correct behavior of 404 not to change the URL in the browser. For redirects we have 30x http status codes. But you can't send two http status codes at the same time (404 and 301).
It is kind of bad practice to redirect to a homepage instead of showing a 404-not found message. The users may be irritated, asking themselves why they are now on the homepage and not at the URL they typed in...

Resources