Open web application in new browser window from command line with POST
Introduction
This post reproduces steps from Open chrome with method Post body data on specific Url.
Approach
-
Create HTML form with POST.
-
Set form submission event to “onload” - submit form once html is opened
-
Convert html form into BASE64
-
Launch new browser window from command line and provide target URL as Data URL format using BASE64 version of HTML form
Detailed example
As an exmaple will be using a SpringBoot app which has to be opened/launched by submitting POST request to “/newbook” endpoint (which creates a new book).
Target App (the one to be opened)
Spring MVC App which opens “ok” page/screen upin POST request which creates new book.
HTML Form with POST
<body onload="document.getElementById('bookForm').submit()">
<form action=http://localhost:8080/newbook id="bookForm" method="post">
<input name="name" value="book145">
<input name="desc" value="desc2345">
<input name="year" value="2025">
<input type="submit" value="go">
</form>
</body>
HTML form encoded in BASE64
PGJvZHkgb25sb2FkPSJkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgnYm9va0Zvcm0nKS5zdWJtaXQoKSI+DQogICAgPGZvcm0gYWN0aW9uPSJodHRwOi8vbG9jYWxob3N0OjgwODAvbmV3Ym9vayIgaWQ9ImJvb2tGb3JtIiBtZXRob2Q9InBvc3QiPg0KICAgICAgPGlucHV0IG5hbWU9Im5hbWUiIHZhbHVlPSJib29rMTQ1Ij4NCiAgICAgIDxpbnB1dCBuYW1lPSJkZXNjIiB2YWx1ZT0iZGVzYzIzNDUiPg0KICAgICAgPGlucHV0IG5hbWU9InllYXIiIHZhbHVlPSIyMDI1Ij4NCiAgICAgIDxpbnB1dCB0eXBlPSJzdWJtaXQiIHZhbHVlPSJnbyI+DQogICAgPC9mb3JtPg0KICA8L2JvZHk+
Launch web app from command line
msedge.exe data:text/html;base64,PGJvZHkgb25sb2FkPSJkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgnYm9va0Zvcm0nKS5zdWJtaXQoKSI+DQogICAgPGZvcm0gYWN0aW9uPSJodHRwOi8vbG9jYWxob3N0OjgwODAvbmV3Ym9vayIgaWQ9ImJvb2tGb3JtIiBtZXRob2Q9InBvc3QiPg0KICAgICAgPGlucHV0IG5hbWU9Im5hbWUiIHZhbHVlPSJib29rMTQ1Ij4NCiAgICAgIDxpbnB1dCBuYW1lPSJkZXNjIiB2YWx1ZT0iZGVzYzIzNDUiPg0KICAgICAgPGlucHV0IG5hbWU9InllYXIiIHZhbHVlPSIyMDI1Ij4NCiAgICAgIDxpbnB1dCB0eXBlPSJzdWJtaXQiIHZhbHVlPSJnbyI+DQogICAgPC9mb3JtPg0KICA8L2JvZHk+