代码如下: public class Lan {
public static void main(String[] args) throws UnknownHostException, IOException {
Socket s = new Socket ("www.sina.com",80);
System.out.println("连接成功 ");
PrintStream s1 = new PrintStream(s.getOutputStream());
System.out.println("连接成功");
s1.println("GET /index.html HTTP/1.1");
s1.println("Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
s1.println("Accept-Language: zh-cn");
s1.println("Accept-Encoding: gzip, deflate");
s1.println("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; KuGooSoft)");
s1.println("Host: localhost:80");
s1.println("Connection: Keep-Alive");
s1.println();
s1.flush();
BufferedReader s2 = new BufferedReader(new InputStreamReader(s.getInputStream()));
String s3 = null;
while((s3=s2.readLine())!=null){
System.out.println(s3);
}
s2.close();
}
}以上程序运行后~会想sina服务器发送相应的请求信息~
但SINA服务器收到我的请求信息后给我的不是它的主页面的HTML代码~而是一个403 forbiend的错误页面~请教下~
我要是想sina服务器给我正确的主页面的HTML代码~该怎么做呢???在线等!!!万分感谢!
public static void main(String[] args) throws UnknownHostException, IOException {
Socket s = new Socket ("www.sina.com",80);
System.out.println("连接成功 ");
PrintStream s1 = new PrintStream(s.getOutputStream());
System.out.println("连接成功");
s1.println("GET /index.html HTTP/1.1");
s1.println("Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
s1.println("Accept-Language: zh-cn");
s1.println("Accept-Encoding: gzip, deflate");
s1.println("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; KuGooSoft)");
s1.println("Host: localhost:80");
s1.println("Connection: Keep-Alive");
s1.println();
s1.flush();
BufferedReader s2 = new BufferedReader(new InputStreamReader(s.getInputStream()));
String s3 = null;
while((s3=s2.readLine())!=null){
System.out.println(s3);
}
s2.close();
}
}以上程序运行后~会想sina服务器发送相应的请求信息~
但SINA服务器收到我的请求信息后给我的不是它的主页面的HTML代码~而是一个403 forbiend的错误页面~请教下~
我要是想sina服务器给我正确的主页面的HTML代码~该怎么做呢???在线等!!!万分感谢!
就用socket来实现通信的~但是我这个例子访问sina服务器时,它不给我主页的HTML代码~
有什么方法能实现么?