HttpURLConnection的connect()方法作用
如题,我用下面的代码可以实现往服务器端传递数据,
URL url = new URL("http://localhost:8088/Test/streamtestserver.do");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/stream");
con.setDoOutput(true);
con.setDoInput(true);
con.setUseCaches(false);
con.setInstanceFollowRedirects(true);
con.connect();
DataOutputStream d = new DataOutputStream(con.getOutputStream());
d.write("111".getBytes());
d.flush();
d.close();
但是我把con.connect();注掉后仍可以实现,所以不知道con.connect();的用处和在,是不是只要
url.openConnection();后就已经建立连接了?
还有一个问题就是我把d.flush()和d.close()方法去掉后仍可以向服务器端输出数据,那d.flush()的用处是什么?
URL url = new URL("http://localhost:8088/Test/streamtestserver.do");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/stream");
con.setDoOutput(true);
con.setDoInput(true);
con.setUseCaches(false);
con.setInstanceFollowRedirects(true);
con.connect();
DataOutputStream d = new DataOutputStream(con.getOutputStream());
d.write("111".getBytes());
d.flush();
d.close();
但是我把con.connect();注掉后仍可以实现,所以不知道con.connect();的用处和在,是不是只要
url.openConnection();后就已经建立连接了?
还有一个问题就是我把d.flush()和d.close()方法去掉后仍可以向服务器端输出数据,那d.flush()的用处是什么?
...全文
相关推荐
Android25图灵聊天项目------HttpURLConnection请求get文本数据
http请求在Android开发中是必不可少的,现在我写了一个关于http get请求文本数据的例子希望能和大家交流学习
使用HttpURLConnection访问web页面[文].pdf
使用HttpURLConnection访问web页面[文].pdf
Android 判断网络状态实例详解
主要介绍了Android 判断网络状态实例详解的相关资料,需要的朋友可以参考下
Android从网上获取图片的简单示例
blog:http://blog.csdn.net/u013293125/article/details/50821983
Android通过URL跟web服务器通信方式(3.0以上通用).pdf
Android通过URL跟web服务器通信方式(3.0以上通用).pdf


Java SE
