How to save a bookmark in Firefox with POST data?

Use a bookmarklet. For example, you can use the tool at http://userjs.up.seesaa.net/js/bookmarklet.html to create a bookmarklet with the following code:

(function(){
  var post_to_url = function(path, params, method) {
    var openWindow = window.open(path);
    method = method || "post"; 
    var form = openWindow.document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", path);
    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);
    }
    openWindow.document.body.appendChild(form);
    form.submit();
  };
post_to_url(
  'http://www.chronopost.fr/transport-express/livraison-colis/engineName/search/accueil/suivi', 
  {search:'test'});
})()

Then use the generated bookmarklet link as a bookmark in your favorite browser. When you click it, it will open a window, create a form with the parameters {search:'test'}, and submit that form.

To change the URL and parameters, just tweak that last call to post_to_url.

This strategy can be great if you just need to create the bookmark once and use it a lot of times. However, it doesn't make it terribly easy to create new bookmarks if you need to do that on a regular basis.


Using the answer by @StriplingWarrior, I've change the script a little bit to have the same behavior as the normal bookmarks by opening the bookmark on the same window

(function(){
  var post_to_url = function(path, params, method) {
    method = method || "post"; 
    var form = window.document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", path);
    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);
    }
    window.document.body.appendChild(form);
    form.submit();
  };
post_to_url(
  'http://192.168.0.1/goform/login', 
  {loginPassword:'password',loginUsername:'admin'});
})()

Using the tool in http://userjs.up.seesaa.net/js/bookmarklet.html you can just copy and paste the code, change the url and parameters and add the generated bookmmarklet to your bookmarks. This is pretty useful to access for example your router control panel.


Simplest approach:

Bookmarklet with filled form and autoupload

javascript:'<html><body onload="document.forms[0].submit()"><form action="http://www.example.com" method="POST"><input name="whatever" value="whatever" type="hidden"></form></body></html>'

Downside: Chromium would send current webpage URL as HTTP referer. (Firefox and IE would not.)

Why referer matters? Without taking into account privacy concerns, some websites would check referer on POST to protect themselves from malicious requests made by hidden iframe form post.

Alternative approach:

Described here, it's slightly more readable but needs HTML file somewhere, usage will be like:

file:///C:/getToPost?name1=value1&name2=value2#http://url.com/service

When working through locally saved file, referer will not be sent. Even in Chromium.
If the file will be placed on a remote website then referer will be sent and will contain website host and original query string.