post without a form

in Script development
Subscribe to post without a form 6 posts, 2 voices



Descriptor Scriptwright

Maybe I don't quite get GM_xmlhttpRequest, I'm not getting any page or errors either.
I just want to do a post instead of a get request, I can create a form and submit it, but that seems silly.
Do I need to do something with onload? Does it use default browser headers?
I can't seem to find a basic example that actually works (they just say "do something").

 
Descriptor Scriptwright

I think I answered my own question...
I have to direct responseText somewhere, so it seems it would actually just be easier to create a form and submit it.

... I think...

 
alien_scum Scriptwright

This is probably a bit late but here's some code I use for checking my mail, it's runnable but it needs a proper url to do something useful as I've purged the personal data.

  GM_xmlhttpRequest({
    method: 'POST',
    headers: {
        'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
        'Content-type': 'application/x-www-form-urlencoded'
    },
    url: 'https://webmail.hoard.com/imp/redirect.php',
    data: 'load_frameset=1&autologin=0&mailbox=INBOX&imapuser=myusername&pass=mypassword',
    onload:function(result) {
       var title = result.responseText.match(/<title>\D*(\d+)\D*<\/title>/);
       if (title) show(title[1])
    }
  });
</title>

I think the default headers are the normal Firefox ones, and all the parameters are optional except method and url so if you just want to submit something and don't care about what comes back you could strip it down to the following

  GM_xmlhttpRequest({
    method: 'POST',
    url: 'https://webmail.hoard.com/imp/redirect.php',
    data: 'load_frameset=1&autologin=0&mailbox=INBOX&imapuser=myusername&pass=mypassword',
  });
 
Descriptor Scriptwright

Not too late, actually that's what I tried, except documentation said 'Content-type' is required, maybe I did something else wrong...


var page = window.location.href;
GM_xmlhttpRequest({
method: 'POST',
url: page,
headers: {
'User-agent': window.navigator.userAgent,
'Content-type': 'application/x-www-form-urlencoded',
},
data: 'name=value'
});

I can see that headers shouldn't be required, so I can try that.
The only other thing is that I used an upper case POST and the form is lower case, but even if the server didn't like that I should still get something? Even if the post request failed it should be the same as pressing "Go", I would expect.
I think the browser sends method upper case
I'm using greasemonkey-0.6.6-mod.xpi for SeaMonkey, but this was supported in 6.6 wasn't it?

 
alien_scum Scriptwright

I've just tried it with my server and it seems to work fine, the only thing that look suspicious is the

var page = window.location.href;

as the url for the current page probably isn't where you want to POST to and even if it is location.href will include all the junk from the URI

POST should be upper case and as for 0.6.6 it has GM_xmlhttpRequest i would recommend adding

onload:function(res){alert(res.responseText)}

to see what (if anything) comes back

 
Descriptor Scriptwright

POST and GET return different responses.
I'll try it on my own server where I can watch the logs, just making sure I was doing it right.
Thanks.