In my application, I need to have a button which opens Firefox (if not already open), executes a POST request including a file upload, and displays the resulting page to the user (for further navigation).
From what I've found until now, this seems to necessitate the use of a Firefox extension like MozRepl or JSSH, so I can connect to the process via Telnet or SSH from my application. Are there other ways? I'm open to good suggestions...
I would then need to use content.XMLHttpRequest to create a POST request:
var req = new XMLHttpRequest();
req.open("POST", "http://myurl", true);
// [...]
req.send()
But what comes in [...]? There is somehow a File object that is built from local forms; but how can I instantiate and fill one myself? And how do I get the page results to show up in Firefox?
I can either write a temporary file to disk and read it from there, or write the file contents directly via Javascript/MozRepl, both are acceptable for me (but 1) probably not for Javascript).
Thanks in advance, -M.
From the command line you can open a page that will contain filled form and JavaScript that would trigger this form to post. XSS protection only applies to background XMLHttpRequest, it's ok if you are posting a form and automatically move browsing to that page.
So you should open a webpage that would upload a form.
But you aren't even forced to create this webpage separately, you may set it with JavaScript directly in place of URL, just like bookmarklets work:
firefox "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>'"
Or you can create an HTML file that would redirect GET to POST, then usage would be like follows:
file:///C:/getToPost?name1=value1&name2=value2#http://url.com/service
This technique is described at this superuser answer with source code for such file.
Note that this HTML file isn't forced to be local, it may be placed on remote server. But take into account that in case of remote file browser would notify final website about your redirecting page as HTTP Referer.