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;
}
可是我在浏览器中输入要访问的地址是没有问题的服务器端能正常输出值
http头是对的啊
囧!
------解决方案--------------------
Content-Length是需要服务器设置吧
resultCode对吗
客户端应该没什么问题。
------解决方案--------------------
StreamConnection 不会有 content-length:0