I'm trying to POST to a html form using a java application. The form is on a page, with html extension if that matters (eg. http://www.domain.tld/somepage.html), holding a form as follows:
<Form method="POST"> <input type="hidden" name="op" value="checkfiles"> <Textarea name="list" rows=12 style="width:100%;font:12px Arial"></Textarea> <br><input type="submit" name="process" value="Check"> </Form> I tried with Apache HTTPComponents, but so far my attempts have been unsuccessful. Here's the function I'm using:
private static void submit(String text) throws Exception{ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.domain.tld/somepage.html"); List <NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("list", text)); httppost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); HttpResponse response = httpclient.execute(httppost); BufferedReader rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line); } System.out.println(result.toString()); } For some reason, this returns me the page at http://www.domain.tld/. Help please.