C
C. Kindle
is it possible for a java application to enter values in a html form, post
it, and reading the resulting html document, e.g. google.com? it seems that
the other side has to be some kind of cgi-script or it doesn't work. i found
an example at
http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html,
but trying it with google, or any other html form, it doesnt work.
source:
=====
public void doPost(){
String queryValue = URLEncoder.encode("java");
try {
URL url = new URL(http://www.google.com);
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
PrintWriter out = new PrintWriter(
connection.getOutputStream());
out.println("q=" + queryValue);
out.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(
connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
catch(Exception e) {
//On exception output error message
System.out.println("url connection error");
}
}
it, and reading the resulting html document, e.g. google.com? it seems that
the other side has to be some kind of cgi-script or it doesn't work. i found
an example at
http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html,
but trying it with google, or any other html form, it doesnt work.
source:
=====
public void doPost(){
String queryValue = URLEncoder.encode("java");
try {
URL url = new URL(http://www.google.com);
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
PrintWriter out = new PrintWriter(
connection.getOutputStream());
out.println("q=" + queryValue);
out.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(
connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
catch(Exception e) {
//On exception output error message
System.out.println("url connection error");
}
}