我在学j2se可只有j2me的教程 已经写了j2me的,可以帮忙写一下j2se的吗
try {
HttpConnection hc; hc = (HttpConnection) Connector.open("http://localhost:998/index.html"); System.out.println(hc.getResponseMessage());
System.out.println(hc.getRequestMethod());
System.out.println(hc.getHost());
System.out.println(hc.getURL());
System.out.println(hc.getResponseCode());
hc.setRequestMethod( HttpConnection.POST);
//得到信息
DataInputStream dis= hc.openDataInputStream();
int length = (int) hc.getLength();
byte[] b = new byte[length];
dis.read(b);
String s= new String (b);
System.out.println(s);
f.append(s);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
HttpConnection hc; hc = (HttpConnection) Connector.open("http://localhost:998/index.html"); System.out.println(hc.getResponseMessage());
System.out.println(hc.getRequestMethod());
System.out.println(hc.getHost());
System.out.println(hc.getURL());
System.out.println(hc.getResponseCode());
hc.setRequestMethod( HttpConnection.POST);
//得到信息
DataInputStream dis= hc.openDataInputStream();
int length = (int) hc.getLength();
byte[] b = new byte[length];
dis.read(b);
String s= new String (b);
System.out.println(s);
f.append(s);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
登入后 自动关闭只是学习一下
请给你一个好吗
楼上几位误导楼主了
HttpURLConnection con = (HttpURLConnection)url.openConnection();
....