62,621
社区成员
发帖
与我相关
我的任务
分享 String keyStore = "d:/keys/clientkey";
String keyPass = "123456";
String trustStore = "d:/keys/clienttrust";
String trustPass = "123456";
SSLSocketFactory ssf = getSSLSocketFactory(keyStore, keyPass,
trustStore, trustPass);
Socket s = ssf.createSocket(
InetAddress.getByName("10.167.228.213"), 9500);
SSLSocket ss = (SSLSocket) s;
ss.startHandshake();
String str = "GET / HTTP/1.1\r\n";
str = str + "Accept: */*\r\n";
str = str + "Accept-Language: ja-JP\r\n";
str = str
+ "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)\r\n";
str = str + "Accept-Encoding: gzip, deflate\r\n";
str = str + "Host: \r\n";
str = str + "Connection: Keep-Alive\r\n";
str = str + "\r\n";
BufferedInputStream dis = new BufferedInputStream(ss.getInputStream());
// BufferedReader bf=new
// BufferedReader(newInputStreamReader(ss.getInputStream()));
DataOutputStream dos = new DataOutputStream(ss.getOutputStream());
BufferedInputStream bis;
dos.write(str.getBytes());
dos.flush();
byte[] data = null;
// long start = System.currentTimeMillis();
// long time = 0;
System.out.println(dis.available());
while (true) {
if (dis.available()> 0) {
byte[] tempdata = new byte[1600];
int charcount = dis.read(tempdata);
if (data == null) {
data = new byte[charcount];
System.arraycopy(tempdata, 0, data, 0, charcount);
} else {
byte[] tempbyte = new byte[data.length + charcount];
System.arraycopy(data, 0, tempbyte, 0, data.length);
System.arraycopy(tempdata, 0, tempbyte, data.length,
charcount);
data = tempbyte;
}
if (charcount < 1600 || dis.available() <= 0) {
break;
}
}
// time = System.currentTimeMillis() - start;
}
System.out.println(new String(data));