星期六 2006年07月15日
实现向网页中的表单提交数据
终于可以实现向网页中的表单提交数据了。。得到返回的结果。。。
<form action="http://A" method="post" name="searchform1" target="_blank" id="searchform1" onsubmit="return SearchForm_onsubmit()" language="javascript">
<input type="hidden" name="B" value="C">
</form>
import java.io.*;
import java.net.*;
public class Post {
public static void main(String[] argv) throws Exception {
URL url = new URL("http://A");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
PrintWriter out = new PrintWriter(connection.getOutputStream());
// encode the message
String name = URLEncoder.encode("B", "UTF-8");
String value = URLEncoder.encode("C", "UTF-8");
// send the encoded message
out.print(name+'='+value);
out.close();
BufferedReader in
= new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
}
呵呵。。接下来要对下下来的东西进行解析了。。用正折表达式。或者用开源的包。现在开始做了