// loginUrl是一个URL对象
HttpsURLConnection loginConn = (HttpsURLConnection) 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());
System.out.println(loginConn.getRequestProperty("User-Agent"));
InputStream input = loginConn.getInputStream();
System.out.println(loginConn.getRequestProperty("User-Agent"));
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(input, charset));
for (String line; (line = reader.readLine()) != null;) {
// 做点啥事情。
}
} finally {
reader.close();
}
标准输出居然显示:
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)
Java/1.5.0_14
而且服务器端接收到的也是Java/1.5.0_14,挺奇怪的。
如果我使用GET请求方式一切都正常。谁能指点一下?
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)有些网页输出:
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)
Java/1.5.0_14这到底是怎么一回事啊!!?
我知道,我这个程序是模仿浏览器发送一个HTTP请求,User-Agent是我设置的,但设置后不起作用。