我在写一个客户端程序,它和Web服务器连接完成一些数据交互。这个网站是用.net写的,并只允许IE浏览器访问(后台应该有识别浏览器类型并作出相应处理的逻辑)。我在请求页面时,把HTTP请求的User-Agent头部做了这样的设置:
URLConnection supConn = supUrl.openConnection();
supConn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)");
在请求这个网站的首页时能返回正常的信息,但在登录网站时却给我返回“该站点只支持IE浏览器访问”的信息,让我很郁闷。我想问一下除了检查HTTP的User-Agent请求头部,还有其它方法识别客户端浏览器类型吗?另外,这个站点使用了ActiveX控件,会不会和这个有关系?
URLConnection supConn = supUrl.openConnection();
supConn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)");
在请求这个网站的首页时能返回正常的信息,但在登录网站时却给我返回“该站点只支持IE浏览器访问”的信息,让我很郁闷。我想问一下除了检查HTTP的User-Agent请求头部,还有其它方法识别客户端浏览器类型吗?另外,这个站点使用了ActiveX控件,会不会和这个有关系?
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/x-ms-xbap, application/x-ms-application, */*..
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727)..
Host: www.xxxx.com.cn
Connection: Keep-Alive
URLConnection loginConn = loginUrl.openConnection();
loginConn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)");
loginConn.setRequestProperty("Cookie", cookie);
loginConn.setDoOutput(true);
OutputStream output = null;
String body = String.format("LoginName=%s&LoginPassword=%s&MBKPassword=&RndPassword=%s&Login_my=94883451&LoginHardware=941244dc8f8f095e0598d310f4acbce16116a5c81b46535b18a65961fc878446&isr=0&key=600CAAB8F72E37825307F2F7D8DAC726", username, password, code);
output = loginConn.getOutputStream();
output.write(body.getBytes());
InputStream input = loginConn.getInputStream();
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(input, charset));
for (String line; (line = reader.readLine()) != null;) {
System.out.println(line);
}
} finally {
reader.close();
}
System.out.println(loginConn.getRequestProperty("User-Agent"));
标准输出居然是Java/1.5.0_14,我这个代码没问题吧,假如我把HTTP请求方式改为GET就没有问题了,这是怎么回事?
这个ActiveX可能只是一个密码输入的插件。