socket和URLConnection

这两者都可以发送消息流,URLConnection是socket的高层封装。

URLConnection使用
get>:
  HttpURLConnection conn = url.openConnection();
  int responseCode = conn.getResponseCode();
  ...
post>:
  HttpURLConnection conn = url.openConnection();
  conn.setRequestProperty("Content-Length",100);
  ...
  out = conn.getOutputStream();
  out.write(...);
  out.flash();
  int responseCode = conn.getResponseCode();
  int resLen = conn.getContentlength();
  in = conn.getInputStream();
  ...
 

posted on 2012-11-05 17:54  5567  阅读(206)  评论(0编辑  收藏  举报