When I try to make a POST request from postman to a Cloudflare worker, the worker treats the request I am making as a GET request and therefore the information I send through POST is also not arriving in the request.
Example:
Client request
const init = {
method: ‘POST’,
headers: headers,
body: content
}
const response = await fetch(‘https://example.com’, init)
Worker Script
async function handleRequest(event) {
return new Response(event.request.method, { status: 200 })
// Show GET method instead POST method
if (request.method !== "POST") {
return new Response("handels POST requests only", {
status: 405,
});
}
And it worked perfectly until recent worker script release. Now I see the following responses in logs (client side, unchanged):
ApiError: Call failed to endpoint POST http:/.../api/save # <--POST here proves it should be post
Response code: 405
Server error: handels POST requests only
In Cloudflare logs I see that it receives GET requests:
So looks like the issue somewhere in HTTP to HTTPS conversion that happens before the worker receives request. This is visible in my previous message: in CF logs GET HTTPS but the client sends POST HTTP
When you make a POST to the http:// URL, you likely get a 301 response redirecting to the https:// version. When an HTTP client gets a 301 response to a POST request, the client will perform a GET request to the redirect URL. The only 3xx response that preserves the method is 307.