http头content-length

来源:互联网 发布:淘宝图片空间协议 编辑:程序博客网 时间:2024/06/05 09:17
 
private String getHttp(String url)    {        //url = "http://10.0.0.172:80"+url;        System.out.println("getHttp:"+url);        String re = "";        try{            HttpConnection httpConn = (HttpConnection)Connector.open(url);            //httpConn.setRequestProperty("X-Online-Host",cHost);            httpConn.setRequestProperty("Accept", "*/*");            httpConn.setRequestProperty("Connection", "Keep-Alive");            httpConn.setRequestMethod(HttpConnection.GET);                                    int i = 0;            String message = "";            String key = "";            String value = "";            while ( ( value = httpConn.getHeaderField( i ) ) != null )            {            key = httpConn.getHeaderFieldKey( i++ );            message = message + key + ":" + value + "\n";            }            System.out.println( message );            DataInputStream dis = httpConn.openDataInputStream();            byte messages[];            int length = (int)httpConn.getLength();            messages = new byte[length];            dis.readFully(messages);            re = new String(messages);            httpConn.close();        } catch (Exception e){            System.out.println(e.toString());            e.printStackTrace();        }         return re;    }

原创粉丝点击