2012-07-12 101 views
0

下面的代码指定我们可以在黑莓中创建http连接以及如何将html页面存储为字符串?我们如何在存储卡/手机内存中将黑莓页面存储到黑莓手机中的sqlite?

我这样做,但我能够得到该http请求,但是当我得到响应,即http_ok​​这是不正确的,这样我可以保存文本噢html作为一个字符串,我可以进一步存储到sqlite。

LabelField title = new LabelField("SQLite Create Database Sample", 
       LabelField.ELLIPSIS | 
       LabelField.USE_ALL_WIDTH); 
       setTitle(title); 
       add(new RichTextField("Creating a database.")); 
       argURL="https://www.google.com:80"; 
      try { 
       connDesc = connFact.getConnection(argURL); 
       if (connDesc != null) { 

        httpConn = (HttpConnection) connDesc.getConnection(); 
        // //Send Data on this connection 
        // httpConn.setRequestMethod(HttpConnection.GET); 
        // //Server Response 
        StringBuffer strBuffer = new StringBuffer(); 
        inStream = httpConn.openInputStream(); 
        int chr; 
        int retResponseCode = httpConn.getResponseCode(); 
        if (retResponseCode == HttpConnection.HTTP_OK) { 
         if (inStream != null) { 
          while ((chr = inStream.read()) != -1) { 
           strBuffer.append((char) chr); 
          } 
          serverResponceStr = strBuffer.toString(); 
          // appLe.alertForms.get_userWaitAlertForm().append("\n"+serverResponceStr); 

          //returnCode = gprsConstants.retCodeSuccess; 
         } 
        } else { 
         //returnCode = gprsConstants.retCodeNOK; 
        } 
       } 
      } catch (Exception excp) { 
       //returnCode = gprsConstants.retCodeDisconn; 
       excp.printStackTrace(); 
      } `enter code here` 

回答

0

代码不执行任何数据库功能,但是我测试,它成功地执行一个HttpRequest外部URL。返回的数据基于您提出请求的服务器的响应。

我使用的代码可以在这里找到: http://snipt.org/vrl7

唯一的改动是保持各种事件的运行总结,并响应显示在RichTextField。基本上,这看起来像预期的那样工作,并且由此产生的字符串应该能够被保存,然而您认为合适;尽管在保存到数据库时可能需要谨慎编码,以免特殊字符丢失或被误解。