26

I would like to save as a Firefox bookmark a page which is not accessible using GET. The only way to retrieve the page is to send some POST data.

For example, I would like to bookmark a Chronopost parcel tracking page, which only allows POST for entering parcel numbers.

Does anyone know a Firefox extension, or some other technique, which would allow me to do this?

1
  • Just a geek note: GET requests aren't supposed to change data, that's why you can bookmark them and can call them as often as you like. POST requests are allowed to change state on the server, which is why they're not easily bookmarked. On POST links you bookmark, think about if calling them multiple times will cause problems, such as buying an extra item from Amazon. May 19, 2012 at 18:32

10 Answers 10

21

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.

4
  • Don't you need the ' around search in {search:'test'} ? Jan 10, 2013 at 21:38
  • 1
    @mezhaka: No. Because this is actually being evaluated as javascript, rather than a JSON string, quotes around property names are optional unless the property name includes a space or a special character. Jan 10, 2013 at 22:13
  • 1
    Thanks for the reply. Do you if I need to url quote my key:values? Like if I have spaces or non ASCII characters in my keys and values is that enough to have it surrounded by '' or do I also need to take care of quoting symbols like ö? Jan 10, 2013 at 22:39
  • @mezhaka: Here are the rules: stackoverflow.com/a/9568622/120955. Jan 10, 2013 at 23:33
4

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.

4

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.

4

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):

  1. Open the page with the form you want to bookmark and fill in the form in a "typical" way. Do NOT submit yet.
  2. Open the Web-Developer Tools -> Network Analysis.
  3. 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".
  4. 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.

2
2

The frmget bookmarklet works for the many sites that are indifferent to the http method: apply the bookmarklet, submit the form, bookmark the result page.

For sites that do require POST, there's this extension, which is not terribly user friendly. You can combine it with frmget: apply frmget, submit the form, bookmark the page, copy the GET parameters into the description field, prefixed with POSTDATA=.

1

I modified a little the script supplied by @StriplingWarrior to accept a HAR file as parameter. The HAR file can be saved from Chrome's Developer Tools (Ctrl+Shift+J).

First open the page with the form data already posted, then right click the first document on the Network tab and select "Copy entry as HAR". Then paste the content on the script below:

<html><body><script>
function dopost() {
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", har["request"]["url"]);
var params = har["request"]["postData"]["params"];
for(var e in params) {
    var hiddenField = document.createElement("input");
    hiddenField.setAttribute("type", "hidden");
    hiddenField.setAttribute("name", params[e]["name"]);
    hiddenField.setAttribute("value", params[e]["value"]);
    form.appendChild(hiddenField);
}
document.body.appendChild(form);
form.submit();
}
window.onload=dopost;

var har=
//-----PASTE HERE------

</script>
</body></html>

Save this as a html file and it should open the posted form. This don't work if the site uses viewstate or if it checks the referrer.

1

Use the iMacro plugin, available for Firefox and Chrome.

0

From what I understand about post, there's no way to record that data yourself and re-send it.

I suggest getting an add-on that fills out forms for you better than firefox does by default.

Chrome actually has a very powerful form recognition and filling out feature built in, but i'm sure there is a firefox addon that does the same thing.

Try this one, it looks promising: Form Saver Firefox Add-on

2
  • But sadly Chrome doesn't offer to save passwords for generic HTTP AUTH pages.
    – qroberts
    Oct 18, 2010 at 18:50
  • Lazarus is better than form saver nowadays.
    – Tobu
    Dec 18, 2012 at 12:36
0

I use this Firefox Addon to bookmark POST actions.

0

Based on user's bookmarklet:

This seems to work for UPS with Firefox and a keyword for the search bar (e.g. "ups XYZ" where XYZ then goes into the %s placeholder inside the bookmarklet) :

javascript:'
<html><body%20onload="document.forms[0].submit()">
  <form%20action="https://wwwapps.ups.com/WebTracking/track"%20method="POST">
  <input%20name="trackNums"%20value="%s"%20type="hidden">
  <input%20name="track.x"%20value="anything"%20type="hidden">
  </form>
</body></html>'

(note this has to be one line)

See also:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .