3

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.

meow
  • 925
  • 7
  • 22
  • 1
    In which language is your application? It's mostly related to it. I don't think you want to open firefox, but the user's browser. – Florian Margaine Jun 29 '12 at 16:45
  • True, but it will be an in-house application and we use Firefox here. So I would limit myself to Firefox since there is probably no generic solution to do this in all browsers... (That's the world of academic scientific software.) Edit: Language is mainly R for the part that does the work, and RExcel/VBA for the frontend. (No, I don't really like RExcel nor VBA, FWIW :) ) – meow Jun 30 '12 at 10:00

3 Answers3

2

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.

Community
  • 1
  • 1
user
  • 23,260
  • 9
  • 113
  • 101
0

Couldn't you do a GET request to another page on your server that contains AJAX code that sends to the POST request? You can always open a browser with any url that may include a querystring without any fancy API (i.e. system('firefox.exe http://stackoverflow.com'). That way, you wouldn't need to worry about browser interaction.

Beyond that, why not just make the POST request in your application and display the results in the app?

Lusitanian
  • 11,012
  • 1
  • 41
  • 38
  • Hm, the point is that the server is not *my* server, it's a publicly available database with web frontend. We do host an instance of the server app ourselves, but really building in a workaround by adding proprietary stuff on the server side would not be my favorite solution. – meow Jun 30 '12 at 10:06
  • > Beyond that, why not just make the POST request in your application and display the results in the app? Because this would mean I had to provide a decent interface to the user to continue browsing around from the result page. And that's probably the last thing I want to spend time on :) The software is intended to make a SOAP query first and display the results itself - if the user finds them interesting, he should be able to further explore them in the more advanced interface provided by the web app, which is beyond the scope of my app. – meow Jun 30 '12 at 10:08
0

From the command line:

firefox --new-window www.example.com

Will open up a new window of Firefox, and navigate to the URL you give it. It sounds like you can just use your POST target as the URL, but if not you could always go to a page that makes a $.POST call.

machineghost
  • 33,529
  • 30
  • 159
  • 234
  • _>but if not you could always go to a page that makes a $.POST call._ When I tried this was unsuccessful, perhaps because of XSS security issues? – meow Jul 03 '12 at 15:10