Ok, I used the TamperData firefox add-on to monitor my GM_xmlhttpRequests
(which were sending the postdata) to see what they were doing differently.
The difference was four headers. Where jQuery sent
Accept: */*
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://localhost:4567/
GM_xmlhttpRequest
sent:
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Content-Type: text/plain; charset=UTF-8
Using the headers:
parameter I was able to specify the Content-Type
of my GM_xmlhttpRequest
, which got it to work.
// ==UserScript==
// @name PostDataTest
// @namespace Test
// @description Simple test of GM_xmlhttpRequest's data parameter
// @include http://localhost:4567/
// @version 1
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @grant metadata
// @grant GM_xmlhttpRequest
// ==/UserScript==
var url = '/?q0=0&q1=1';
var data = 'd0=0&d1=1'
GM_xmlhttpRequest({
method: 'POST',
url: url+'gm',
data: data+'gm',
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
onload: function(r){
console.log('gm:' + r.responseText);
}});
$.post(url+'jq', data+'jq', function(d,s,r){
console.log('jq:' + r.responseText);
});