一个http协议和iis的疑问,跟微软中国站点有关

Laone 2004-05-01 10:38:19
用java写了一个socket小程序,就是用socket发送http请求,然后获取返回数据
在请求别的网站的时候,都可以返回正确的页面,可是我请求微软的主网站的地址的时候,返回给我的却是400错误,请看具体数据:
http请求http://www.microsoft.com/china/homepage/ms.htm发送的数据包:
GET /china/homepage/ms.htm HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, application/x-gsarcade-launch, */*
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Host: www.microsoft.com:80
Connection: Keep-Alive


服务器返回给我的数据:
HTTP/1.1 400 Bad Request
Content-Type: text/html
Date: Sat, 01 May 2004 14:18:04 GMT
Connection: close
Content-Length: 20

<h1>Bad Request</h1>

这是怎么回事呢?它用了什么技术辨别是IE请求还是自己用socket请求?
...全文
91 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Laone 2004-05-05
  • 打赏
  • 举报
回复
去掉Connection: Keep-Alive也是一样的,java源码如下:
import java.io.*;
import java.net.*;

public class Client{
Socket socket;
BufferedReader in;
PrintWriter out;

public Client(String IPAddr, String httpURL, int Port){
try{
socket = new Socket(IPAddr, Port);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out = new PrintWriter(socket.getOutputStream(),true);
String httpRequest = "GET " + httpURL + " HTTP/1.1\nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, application/x-gsarcade-launch, */*\nAccept-Language: zh-cn\nAccept-Encoding: gzip, deflate\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\nHost: " + IPAddr + ":" + Port + "\n\n";
System.out.println(httpRequest);
out.println(httpRequest);
String result = in.readLine();
while(result!=null){
System.out.println(result);
result = in.readLine();
}
out.close();
in.close();
socket.close();
}
catch (IOException e){
System.out.println("ERRO:"+e.getMessage());
}
}

public static void main(String[] args)
{
if (args.length<3){
System.out.println("useage: java Client hostname url port\n");
}else{
new Client(args[0], args[1], Integer.parseInt(args[2]));
}
}
}
cnzzq 2004-05-04
  • 打赏
  • 举报
回复
Connection: Keep-Alive IS POST CONNECTION
it should be close
cnzzq 2004-05-04
  • 打赏
  • 举报
回复
不允许GET的话你怎么可能在IE中打开呢。
你的GET string有问题啦。
搞HTTP协议可以用抓包软件抓IE的包回来COPY就OK

8,327

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 IIS
社区管理员
  • IIS
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧