2011/01/15

Java HTTP GET using HttpURLConnection


import java.net.HttpURLConnection;
import java.net.URLConnection;
import java.net.URL;
//....
try {
URL u = new URL(STR_URL);
URLConnection uc = u.openConnection();
HttpURLConnection httpuc = (HttpURLConnection)uc;
httpuc.setRequestMethod("GET");

in_stream = con.getInputStream();
out_stream = new FileOutputStream(STR_FILE);

while (-1 != (len = in_stream.read(buffer))) {
out_stream.write(buffer, 0, len);
}

in_stream.close();
out_stream.close();

}catch(Exception e){
//..

0 件のコメント:

コメントを投稿