NOKIA6230i动感卡走CMWAP通过HttpConnection访问WEB URL 的问题,解决再给200分!不胜感激!!!!急~~~~~
public void startApp(){
display.setCurrent(mainForm);
try{
callJsp();
}
catch(Exception e){
System.out.println("Error");
}
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
}
public void callJsp() throws IOException{
HttpConnection http=null;
InputStream iStrm=null;
String url="http://XXX.XXX.XXX.XXX:2059/paixu/test.jsp";
try{
//http://10.0.0.172
http= (HttpConnection) Connector.open("http://XXX.XXX.XXX.XXX:2059/paixu/test.jsp");
// http.setRequestProperty("X-Online-Host","XXX.XXX.XXX.XXX:2059");
mainForm.append("1");
mainForm.append("2");
// http.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.1");
// http.setRequestProperty("Content-Language","en-US");
//http.setRequestProperty("Content-Type","application/octet-stream");
// http.setRequestProperty("Accept","*/*");
// http.setRequestProperty("Connection","Keep-Alive");
http.setRequestMethod(HttpConnection.GET);
mainForm.append("3");
if(http.getResponseCode()==HttpConnection.HTTP_OK){
mainForm.append("4");
iStrm=http.openInputStream();
mainForm.append("5");
int length=(int)http.getLength();
if(length>0){
byte servletData[]=new byte[length];
iStrm.read(servletData);
mainForm.append(new String(servletData));
}
else
mainForm.append("不能访问数据!");
}
}catch(Exception e){
mainForm.append("网络出错");
}
finally{
if(iStrm!=null)
iStrm.close();
if(http!=null)
http.close();
}
}
总是抛出网络出错!!!做过的指点一下!!谢谢~