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