POST ajax request not working with Cloudflare


#1

Hi! When I try to send a POST request the site doesn’t get it, because the cloudflare makes a redirect.
What is the problem, and how can I solve it?


#2

Cloudflare redirects things if you set up page rules to do so or if you turn on the " Always use HTTPS" setting… not sure if there are other cases where it redirects. Does it redirect if you POST the data over https? If so then it’s not due to “Always use HTTPS”.


#3

I use https, and I don’t know what is the problem.
I have Always use HTTPS and Automatic HTTPS Rewrites


#4

Do you have page rules that say to redirect? Are you sure cloudflare is causing the redirect? What is it redirecting to/from?


#5

It is refreshing the page (redirect it to itself) and because of that the POST request won’t be sent.
I have no page rules.


#6

Are you sure cloudflare is doing the redirect? Does it still happen if you disable the cloudflare proxy :grey:?


#7

It worked before the cloudflare.
Update:
It is working with regular form but it isn’t with ajax.


#8

Do you have a sample request that can reproduce the issue?
If you don’t want to share your own domain I don’t mind of you POST against my test domain: https://sixcorners.net


#9

If I make a form with post and submit it, it works perfectly.
But if I send the post via xhr it didn’t work. The server isn’t get the POST.


#10

Can you make a curl that reproduces the issue?


Be aware that the curl might have sensitive info like cookies and stuff… You might want to strip out things that aren’t necessary to reproduce the issue.


#11

Okay, it is working with curl and and jquery. Only not with xmlhttp request.


#12

If you can capture the actual request that has the problem it could make debugging this easier.
What about a .har file? If you can capture what is happening on the network level then you can look at what is different between jquery and xmlhttprequest. I think that would be helpful unless you think this is some kind of javascript api issue.

What about a https://jsfiddle.net/? If you can create a small snippet that recreates the problem then maybe I could help easier.


#13

I think I will use jQuery. It is much better.
It’s just funny that a simple xmlhttprequest did not working.

Update:
I think there is something big problem with my code or site.
The test jquery post request page is working, xmlhttp isn’t but who cares?
But my other pages what does jquery post are not working. The site not get the post fields…
The codes are perfectly working on localhost or vps, without the cloudflare.