首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > BlackBerry >

关于黑莓真机上联网的有关问题(求有真机联网经验的朋友帮帮忙)

2012-02-17 
关于黑莓真机上联网的问题(求有真机联网经验的朋友帮帮忙)下面这段代码是向服务器端POST一条数据的代码,在

关于黑莓真机上联网的问题(求有真机联网经验的朋友帮帮忙)
下面这段代码是向服务器端POST一条数据的代码,在模拟器上使用MDS联网,POST数据成功了,但是一发到外包方(新加坡那边的)进行真机测试死活POST不成功,(由于这边刚开始做Blackberry,没有真机,也没有签名无法测试)
有这方面经验的朋友,帮忙看下代码,看看问题出在哪里,纠结了好多天都没解决,知道的帮忙解决下,非常感谢了。

Java code
    public boolean uploadDataToServer(int golbalTime) throws IOException,            SIMCardException {        // http://applorer.com/nERuGAwepRu3ruDR/tracker/track?os=BlackBerry        // 5.0.0&app=GD121&deviceid=355239030062710&phonenum=91798175&custom1=2        Util                .log("-------GD121>-------------uploadDataToServer------------------------");        HttpCreateUrl httpCreateUrl = new HttpCreateUrl();        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();        String url = "http://applorer.com/nERuGAwepRu3ruDR/tracker/track";        // String url =        // "http://applorer.com/nERuGAwepRu3ruDR/tracker/track;deviceside=true;interface=wifi";        String osVersion = "BlackBerry " + DeviceInfo.getSoftwareVersion();        String appName = Strings.APP_NAME;        String IMEI = getIMEI();        String phoneNumber = getSIMPhoneNumber();        HttpConnection hconn = null;        OutputStream out = null;        InputStream istrm = null;        try {            StringBuffer content = new StringBuffer("os");            content.append('=');            content.append(new String(osVersion.getBytes(), "UTF-8"));            content.append('&');            content.append("app");            content.append('=');            content.append(new String(appName.getBytes(), "UTF-8"));            content.append('&');            content.append("deviceid");            content.append('=');            content.append(new String(IMEI.getBytes(), "ASCII"));            content.append('&');            content.append("phonenum");            content.append('=');            content.append(phoneNumber);            content.append('&');            content.append("custom1");            content.append('=');            content.append(golbalTime);            String bodystr = content.toString();            if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {                Util.log("==========+WLAN_STATE_CONNECTED+============");                //url = httpCreateUrl.getWifiUrl(url);                url = url+"deviceside=true;interface=wifi";                hconn = (HttpConnection) Connector.open(url);            }            int coverageStatus = CoverageInfo.getCoverageStatus();            switch (coverageStatus) {            case CoverageInfo.COVERAGE_MDS:                Util.log("==========+COVERAGE_MDS+============");                url = httpCreateUrl.getBesMdsUrl(url);                hconn = (HttpConnection) Connector.open(url);                break;            default:                Util.log("==========+default+deviceside=true============");                hconn = (HttpConnection) Connector.open(url                        + ";deviceside=true");            }            Util.log("-------GD121>-------------URL:" + url);            hconn = (HttpConnection) Connector.open(url, Connector.READ_WRITE,                    true);            // UrlRequestedEvent            hconn.setRequestMethod(HttpConnection.POST);            hconn.setRequestProperty(HttpProtocolConstants.HEADER_USER_AGENT,                    "BlackBerry/5.0.0");            hconn.setRequestProperty(                    HttpProtocolConstants.HEADER_CONTENT_LENGTH, String                            .valueOf(bodystr.getBytes().length));            hconn.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_TYPE,                    "application/x-www-form-urlencoded");            out = hconn.openOutputStream();            out.write(bodystr.getBytes());            out.flush();            int responseCode = hconn.getResponseCode();            istrm = hconn.openInputStream();            byte[] buff = new byte[1024];            int len = 0;            while ((len = istrm.read(buff)) != -1) {                outputStream.write(buff, 0, len);            }            outputStream.close();            if (responseCode == HttpConnection.HTTP_OK) {                Util                        .log("-------GD121>success--------uploadDataToServer------------------------");                return true;            } else {                return false;            }        } catch (Exception e) {            System.out.println(e.toString());        } finally {            if (istrm != null)                istrm.close();            if (out != null)                out.close();            if (hconn != null)                hconn.close();        }        return false;    } 



[解决办法]
没做过黑莓的,不过连接不上可能有如下原因:
1.当调用网络JAVA api的时候,数据网络会只动建立连接么(例如GPRS连接,其实是个拨号过程),不需要格外的操作么?
2.是不是需要设置代理,例如像CMWAP接入点,
3.是不是在新加坡就连接不上那个要连接的服务器,可以用PC端工具测试;
4. 测试的机器能上网么,用浏览器试试

[解决办法]
黑莓签名现在不用钱啦,搞个真机测一下啦
[解决办法]
看你用什么方式上了 一般URL后面加suffix 比如说interface = wifi,tcp就用deviceside=true
[解决办法]
http://blog.csdn.net/salvatore_zhang/archive/2010/05/06/5564268.aspx
里边有详细的设置
[解决办法]
谁知道具体的联网方式,我看到有的软件分的很细,联通,移动,电信方式是不是都不一样??
[解决办法]
"http://applorer.com/nERuGAwepRu3ruDR/tracker/track;deviceside=true;interface=wifi";
用这个,真机上开wifi,post不了?什么错误

热点排行