//为什么不能获取 OutputStream 报protocolException
class URLConnectionDemo
{
public static void main(String args[]) throws IOException
{
URL url=new URL("http://192.168.0.110:8080/myweb/Demo.html");
//URLConnection openConnection()
//返回一个 URLConnection 对象,它表示到 URL 所引用的远程对象的连接
URLConnection conn=url.openConnection();//带着协议封装了Socket 到了应用层
//相当于 Socket s=new Socket(ip,port);并把请求数据头封装了
InputStream in=conn.getInputStream();
OutputStream out=conn.getOutputStream();
byte buf[]=new byte[1024];
int len=in.read(buf );
System.out.println(new String(buf,0,len));
}
} |
|