Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  Rich Homolka May 19 '12 at 18:32
add comment

9 Answers

up vote 11 down vote accepted

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.

share|improve this answer
    
Don't you need the ' around search in {search:'test'} ? –  mezhaka Jan 10 '13 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. –  StriplingWarrior Jan 10 '13 at 22:13
    
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 ö? –  mezhaka Jan 10 '13 at 22:39
    
@mezhaka: Here are the rules: stackoverflow.com/a/9568622/120955. –  StriplingWarrior Jan 10 '13 at 23:33
add comment

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=.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
    
But sadly Chrome doesn't offer to save passwords for generic HTTP AUTH pages. –  qroberts Oct 18 '10 at 18:50
    
Lazarus is better than form saver nowadays. –  Tobu Dec 18 '12 at 12:36
add comment

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.

share|improve this answer
add comment

Use the iMacro plugin, available for Firefox and Chrome.

share|improve this answer
add comment

I use this Firefox Addon to bookmark POST actions.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.