String requestUrl = "http://www.baidu.com";
URL url = new URL(requestUrl);
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
uc.setRequestMethod("GET");
uc.setDoInput(true);
uc.setRequestProperty("Accept-Charset", "utf-8");
uc.setConnectTimeout(60000);
已经执行了url.openConnection()了,再设置一些属性还有什么意义?
这里 openConnection()只是打开一个url请求的IO流,如果想要上传或者下载数据需要手动通过IO流操作来完成。
不能单纯的把该方法理解为发送了一个请求。