简体   繁体   中英

Server logs showing GET request right before POST request

When I look through my server logs, I see periodic GET requests coming in instantaneously before the POST request from the same ip with the same referrer. I expect the POST, but not the GET. Has anyone seen this before?

I'm dynamically creating a form inside of an iframe with javascript in order to send the POST request to a server. I can't use Ajax because the POST request is to a different domain. This works on about 95% of the time. 5% of the time I get a GET request just before the POST. It seems to happen repeatedly from the same ip.

Here is the server log:

10.160.42.113 - - [16/Sep/2010:04:33:08 +0000] "GET /pixel HTTP/1.1" 200 2 "url" "Mozilla/5.0 (Windows; U; Windows NT 5.1; hu; rv:1.9.2.9) Gecko/20100824 Firefox/3.6.9 ( .NET CLR 3.5.30729)"
10.160.42.113 - - [16/Sep/2010:04:33:08 +0000] "POST /pixel HTTP/1.1" 200 2 "url" "Mozilla/5.0 (Windows; U; Windows NT 5.1; hu; rv:1.9.2.9) Gecko/20100824 Firefox/3.6.9 ( .NET CLR 3.5.30729)"

Here is the js code:

var iframe = document.createElement("iframe");
iframe.height = "0";
iframe.width = "0";
iframe.frameBorder = "0";
document.getElementById('canvas').appendChild(iframe);


var iframeDocument = iframe.contentDocument || iframe.contentWindow.document || iframe.document;
iframeDocument.open();
iframeDocument.close();


var form = document.createElement("form");
form.setAttribute("action", 'url');
form.setAttribute("method", 'POST');

for (var key in params) {
    var hiddenField = document.createElement("input");
    hiddenField.setAttribute("type", "hidden");
    hiddenField.setAttribute("name", key);
    hiddenField.setAttribute("value", params[key]);

    form.appendChild(hiddenField);
}

iframeDocument.body.appendChild(form);
form.submit();

This is likely a Cross Origin Request Sharing 'preflight' request. See Additional GET requests before POST request that my code isn't making .

You'll need to handle the CORS preflight requests on your web server.

Just a thought - what happens if someone submits the form, then reloads the page, or uses the back/forward buttons on the browser? Might be the case that their browser is trying to "get" the target of the submit when they move backward through the history.

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