62,614
社区成员
发帖
与我相关
我的任务
分享
@Test
public void httpGet(){
try {
// 创建连接
InetAddress addr = InetAddress.getByName("wap.cmgame.com");
int port = 80;
Socket socket = new Socket(addr, port);
// 写入数据
BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(),
"UTF-8"));
wr.write("GET /portalone/LoginWapOnlineGame?serviceID=700016595000&contentCode=000038473000&channelID=14017000&SPID=701023&p=iFrs63fjPmkCAPfLvbdt%2FA2t7DXluIobvfPoB3TNioPhgdPHH7URgnWravnjaeDuhsGvxHEnTMlR8l%2By%2FPnJ6ncdN4SJp%2F2RnqGHe6un7%2FOTq4h1a3%2FYBq%2F4cvrwVHF%2FJc392Tml%2BNab%2BDVVAnsf%2Bq6VYQLTdYgZPoUKKxBslQdk8hjqyeof5YRUAx3jB41v27%2F%2BI0Sb%2BiGTIykHt6rvjkM2d6C8DHk5%2BvdSfqEM%2FhWOfND5oZ2hUuAOkyxG1Hbeblw2fRQxxIKKreu1BP1X4wv9VBqd0P%2F1493kN93EfDMqRsa%2BjBcyiWnVc9ZXLa8ItWHNvsE0IZhwzZxFERgHYuoepcrIX0jfVtr4rVHXyI4%3D HTTP/1.1\r\n");
wr.write("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"+"\r\n");
wr.write("Accept: */*"+"\r\n");
wr.write("Host: wap.cmgame.com"+"\r\n");
wr.write("Cache-Control: no-cache"+"\r\n");
//qqUser.httpClient.Request.UserAgent:= 'WinWAP/3.2 (3.2.1.25; Win32)';
wr.write("\r\n");
wr.flush();
// 创建读取数据的Reader,里面指定了需要的编码类型。
BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream(),
"UTF-8"));
// 读取每一行的数据.注意大部分端口操作都需要交互数据。
String str;
while ((str = rd.readLine()) != null) {
System.out.println(str);
}
rd.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
URL url=new URL("http://wap.cmgame.com/portalone/");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
InputStreamReader isr = new InputStreamReader(bis, "utf-8");
BufferedReader br = new BufferedReader(isr);
String line=null;
while((line=br.readLine())!=null){
System.out.println(line);
}
br.close();
isr.close();
bis.close();
is.close();
conn.disconnect();
}
你哪个连接没有文件