日期:2014-05-20 浏览次数:20891 次
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;
}