I am trying to read a POST result from a certain URL. If the request page (where you will fill out a form and click submit) and the response page (where the result is shown) are the same URL, it is easy. You write the post parameters to the URL and then open an inputstream to read the result. However, how does it work if the request page and the response page are 2 different URL? Since the request page is using POST as the form method, you can't just open the response page and pass paramters after the URL. Anyone has any ideas? Thanks in advance,
Laudney Ren
Ranch Hand
Joined: Jan 06, 2002
Posts: 111
posted
0
You can do it this way: URl url = new URL("http://www.laudney.org/cgi-bin/post-query"); URLConnection uc = url.openConnection(); uc.setDoOutput(true); OutputStreamWriter out = new OutputStreamWriter(uc.getOutputStream(),"ASCii"); out.write(query.toString()); out.write("\r\n"); out.flush(); out.close(); InputStream in = uc.getInputStream(); // read the response from in note: setDoOutput(true) is necessary. out.flush is necessary or the query won't be sent.
" Veni, vidi, vici "<br />" I came, I saw, I conquered "