1 Star 0 Fork 0

seaswalker/practice

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
HttpURLConnectionTest.java 933 Bytes
一键复制 编辑 原始数据 按行查看 历史
seaswalker 提交于 2015-10-09 15:09 +08:00 . 去除源文件BOM头,复习AOP
package net;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpURLConnectionTest {
public static void main(String[] args) throws IOException {
URL url = new URL("http://www.baidu.com");
HttpURLConnection http = (HttpURLConnection) url.openConnection();
//输出服务器相应头部
System.out.println("HTTP/1.1 " + http.getResponseCode() + " " + http.getResponseMessage());
String key = null;
String value = null;
for(int i = 1; ;i ++) {
key = http.getHeaderFieldKey(i);
if(key == null) {
break;
}
value = http.getHeaderField(key);
System.out.println(key + ":" + value);
}
//输出响应的主体内容
System.out.println();
InputStream is = http.getInputStream();
int temp = 0;
while((temp = is.read()) != -1) {
System.out.print((char) temp);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/seaswalker/practice.git
git@gitee.com:seaswalker/practice.git
seaswalker
practice
practice
master

搜索帮助