欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

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

更新时间: 2014-01-05 02:42:52 责任编辑: Author_N1

 

关于黑莓真机上联网的问题(求有真机联网经验的朋友帮帮忙)
下面这段代码是向服务器端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;
    }

 			
			
		
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 02:42:52
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/13480/
本文WWW.DOC100.NET DOC100.NET版权所有。