Paul Taylor
Paul Taylor

Reputation: 13190

How to open webpage in users preferred browser as a post request in Java

Okay so I know how to send a HTTP POST request to a website in code, and I know how to open a url in a browser (HTTP GET). But how do open a HTTP POST in a browser.

EDIT:More Details: The website allows you to open a page to add a new entry, you can seed that page with information by POSTing that information. I have that information in my Java Desktop application, so from my Java application I want to open the add new entry page in the users preferred browser seeded with the known information.

EDIT: SO I tried Lees answer, and managed to construct a webpage with a submit button, when you click on it it goes to the final page with fields filled in, but I cant get javascript to work so that it goes there automtically without needing to press the submit button. Here is the webpage I generate

<html><head>
<script type = "text/javascript">
function onLoad() 
{
    document.getElementById('form').submit();
}
</script>
</head>
<body>
<form name="form" action="http://test.musicbrainz.org/release/add" method="post">
<input name="name" type="hidden" value="Porcupine"/>
<input type="submit" value="send">
</form>
</body>

Upvotes: 6

Views: 10339

Answers (3)

DaShaun
DaShaun

Reputation: 3880

I assume that since you are needing a "POST" you have data to send along. I feel like we don't have all of the information to answer this properly. I'm guessing you know, on the back-end, what the data is that you want posted. I'm also guessing that you don't want a user to have to submit anything manually. I can imagine that you have a user on a page, in the back-end, you have an httpclient that is posting the data for you. On your page, you could have javascript call your servlet (or other) to post the data and provide the output to a new window (or other).

Upvotes: 1

Boris Pavlović
Boris Pavlović

Reputation: 64622

Use Poster addon for Firefox:

"A developer tool for interacting with web services and other web resources that lets you make HTTP requests, set the entity body, and content type. This allows you to interact with web services and inspect the results..."

Or if you prefer Google Chrome.

Upvotes: 0

Lee Kowalkowski
Lee Kowalkowski

Reputation: 11751

As there is no way of POSTing via the address bar, you need to serve a page that contains a HTML form and submits that. You can try formulating a javascript: URI (like a favelet) that builds a HTML form and posts it. But I'm not 100% sure that JavaScript URI's are associated with your preferred browser by the OS. So I'm going to err on the side of "you can't".

But you can GET a page with a form on it and JavaScript that POSTs it. Providing JavaScript is enabled.

Upvotes: 4

Related Questions