当前位置: 技术问答>java相关
求救:关于socket
来源: 互联网 发布时间:2015-04-01
本文导语: 我想通过socket与www.cnnews.com连接,并将www.cnnews.com的内容拉下来,怎么做呢?(不用URL类) 以下是我的程序,但是输不出来,请大家帮忙,谢谢!!! import java.io.*; import java.net.*; public class MyUrl { public static void...
我想通过socket与www.cnnews.com连接,并将www.cnnews.com的内容拉下来,怎么做呢?(不用URL类)
以下是我的程序,但是输不出来,请大家帮忙,谢谢!!!
import java.io.*;
import java.net.*;
public class MyUrl {
public static void main(java.lang.String[] args) {
try {
InetAddress addr = InetAddress.getByName("www.cnnews.com");
Socket s = new Socket(addr,80);
BufferedReader sin =
new BufferedReader(new InputStreamReader(s.getInputStream()));
BufferedWriter sout =
new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
int xx;
while ((xx = sin.read()) !=-1) {
System.out.println(xx);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
以下是我的程序,但是输不出来,请大家帮忙,谢谢!!!
import java.io.*;
import java.net.*;
public class MyUrl {
public static void main(java.lang.String[] args) {
try {
InetAddress addr = InetAddress.getByName("www.cnnews.com");
Socket s = new Socket(addr,80);
BufferedReader sin =
new BufferedReader(new InputStreamReader(s.getInputStream()));
BufferedWriter sout =
new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
int xx;
while ((xx = sin.read()) !=-1) {
System.out.println(xx);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
|
看看rfc协议HTTP/1.0 吧
http://www.china-pub.com/computers/eMook/emooknew/rfctxt/RFC1945.txt
http://www.china-pub.com/computers/eMook/emooknew/rfctxt/RFC1945.txt
|
??为什么不能用URL类!