📄 httpconnection.java
字号:
package com.easyjf.http;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class HttpConnection {
private URLConnection conn;
public HttpConnection()
{
}
public HttpConnection(URLConnection conn)
{
this.conn=conn;
}
public String getHTML()throws IOException
{
BufferedReader readIn = null;
String line;
StringBuffer resultSB = new StringBuffer();
String charset=null;
Pattern p=Pattern.compile("charset=['\"]*([\\w-\\d]*)['\"]*");
//ContentType is like:text/html; charset=utf-8
//System.out.println(conn.getContentType());
if(conn.getContentType()!=null){
Matcher mc=p.matcher(conn.getContentType().toLowerCase());
if(mc.find())charset=(mc.group(1));
}
// System.out.println(charset);
if(charset!=null && (!charset.equals("")))
readIn = new BufferedReader(new InputStreamReader(conn.getInputStream(),charset));
else
readIn = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ( (line = readIn.readLine()) != null) {
resultSB.append(line+"\n");
}
return resultSB.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -