/** * Http连接处理器接口 * @author cleverpig * */ public interface HttpConnectionHandler { //http请求常量 public static final String RQH_HOST="X-Online-Host"; public static final String RQH_ACCEPT="Accept"; public static final String RQH_CONTENT_LANGUAGE="Content-Language"; public static final String RQH_CONTENT_TYPE="Content-Type"; public static final String RQH_CONNECTION_OPTION="Connection"; //http回应常量 public static final String RSH_DATE="Date"; public static final String RSH_SERVER="Server"; public static final String RSH_MODIFIEDDATE="Last-Modified"; public static final String RSH_CONTENT_ENCODING="Content-Encoding"; public static final String RSH_CONTENT_LENGTH="Content-Length"; public static final String RSH_CONTENT_TYPE="Content-Type";
public boolean putRequestHeaderProperty( HttpConnection conn, String key, String keyValue);
public String getResponseHeaderProperty( HttpConnection conn, String key);
public boolean setRequestMethod( HttpConnection conn, String methodName);
public boolean putRequestHeader( HttpConnection conn, Hashtable propertiesPair);
public Hashtable getResponseHeader( HttpConnection conn, String[] propertyNames);
public boolean sendRequestData( HttpConnection conn, Object sendData);
public Object getResponseData(HttpConnection conn);
byte[] data=null; String type=getResponseHeaderProperty(conn,RSH_CONTENT_TYPE); int len = 0; try{ len=Integer.parseInt(getResponseHeaderProperty(conn,RSH_CONTENT_LENGTH)); } catch(Exception ex){ len=0; } if (len > 0) { int actual = 0; int bytesread = 0 ; data = new byte[len]; while ((bytesread != len) && (actual != -1)) { try{ actual = is.read(data, bytesread, len - bytesread); bytesread += actual; } catch(Exception ex){ message=ex.getMessage(); return null; } } } else { int ch; Vector vbuffer=new Vector(); try{ while ((ch = is.read()) != -1) { vbuffer.addElement(new Integer(ch)); } } catch(Exception ex){ message=ex.getMessage(); return null; } len=vbuffer.size(); data = new byte[len]; for(int i=0;i<len;i++){ data[i]=((Integer)vbuffer.elementAt(i)).byteValue(); } }
String result=new String(data); int flagBeginPosition=result.indexOf("charset="); int flagEndPosition=result.indexOf("/">",flagBeginPosition); if (flagEndPosition>flagBeginPosition){ type=result.substring(flagBeginPosition+"charset=".length(),flagEndPosition); } System.out.println("获得html字符集:"+type); if (type!=null){