的HttpConnection不是在真实设备工作-Blackberry [英] HttpConnection not working in real device -Blackberry

查看:185
本文介绍了的HttpConnection不是在真实设备工作-Blackberry的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的code

public String Serverconnection(String url) {

    String line = "";

    if (DeviceInfo.isSimulator()) {
        url = url + ";deviceSide=true";
    }
    try {
        HttpConnection s = (HttpConnection) Connector.open(url);//*i get the exception here*
        s.setRequestProperty("Content-Type",
                "application/x-www-form-urlencoded");
        s.setRequestProperty(
                "Accept",
                "text/html,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
        s.setRequestProperty(HttpHeaders.HEADER_ACCEPT_CHARSET, "UTF-8");
        s.setRequestMethod(HttpConnection.GET);
        InputStream input = s.openInputStream();
        byte[] data = new byte[10240];
        int len = 0;
        StringBuffer raw = new StringBuffer();

        while (-1 != (len = input.read(data))) {
            raw.append(new String(data, 0, len));
        }

        line = raw.toString();

        input.close();
        s.close();
    } catch (Exception e) {
        System.out.println("response--- excep" + line + e.getMessage());
    }
    return line;

}

这code细的工作,当我在模拟器中运行。但在现实设备我得到了异常的细节不可用 - 不支持虚拟机,未指定APN是

this code working fine when i run in the emulator. But in the real device i got the Exception "details unavailable - not supported by VM" "APN is not specified."

我该如何解决这个问题?

How can I fix this?

推荐答案

指的是知识中心文章<一个href=\"http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is_-_Different_ways_to_make_an_HTTP_or_socket_connection.html?nodeid=826935&vernum=0\"相对=nofollow>不同的方法进行HTTP或套接字连接

追加连接字符串您url.Then尝试

Append the connection string to your url.Then try

private static String getConnectionString(){
String connectionString="";
if(WLANInfo.getWLANState()==WLANInfo.WLAN_STATE_CONNECTED){
    connectionString="?;interface=wifi";
}

else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS){
     connectionString = "?;&deviceside=false";
}
else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT)==CoverageInfo.COVERAGE_DIRECT){
    String carrierUid=getCarrierBIBSUid();
    if(carrierUid == null) {
        connectionString = "?;deviceside=true";
    }
    else{
        connectionString = "?;deviceside=false?;connectionUID="+carrierUid + "?;ConnectionType=mds-public";
    }               
}
else if(CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE) {          
        }
    return connectionString;
}

编辑: -

private static String getCarrierBIBSUid()
{
    ServiceRecord[] records = ServiceBook.getSB().getRecords();
    int currentRecord;

    for(currentRecord = 0; currentRecord < records.length; currentRecord++)         {             if(records[currentRecord].getCid().toLowerCase().equals("ippp"))             {                 if(records[currentRecord].getName().toLowerCase().indexOf("bibs") >= 0)
            {
                return records[currentRecord].getUid();
            }
        }
    }

    return null;
}

这篇关于的HttpConnection不是在真实设备工作-Blackberry的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆