简体   繁体   中英

form POST submit requests show up as get requests

We have a javascript/jQuery form which we submit:

var form = jQuery("<form action='http://ourdomain.com/api/setter' method='post' target='response_frame'><input type='text' name='c' value='aaaa'></form>").appendTo(document.body);
form.submit();

Corresponding request shows as GET in the IIS logs (and it is missing "c" value because it was supposed to be in the body). Any hints how POST became GET?

I can't repro it locally, it works as expected with POST, it only shows up in IIS logs in productions.

This is happening because IIS adds trailing slash to URL's which cause a 301 redirection. So POST becomes GET . As a solution try to add a trailing slash to your form action:

var form = jQuery("<form action='http://ourdomain.com/api/setter/' method='post' target='response_frame'><input type='text' name='c' value='aaaa'></form>").appendTo(document.body);
form.submit();

I hope this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM