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.
Thanks to the answers in this question, I found this beautiful add-on for Firefox: Bookmark POST. It lacks a good documentation but this should get you started:
With that bookmark its four easy steps to your bookmarked POST request (no javascript required):
- Open the page with the form you want to bookmark and fill in the form in a "typical" way. Do NOT submit yet.
- Open the Web-Developer Tools -> Network Analysis.
- Submit your form. The submit will show up in the network analyis. There you can select "Edit and send again" and copy the "Request-Body".
- Create a Bookmark to the form page and add the string
POSTDATA={YOUR_REQUEST_BODY_HERE}
as the bookmarks description.
For me this is way easier than to fiddle with Javascript.