开发者

How to get HTML source code from an url in blackberry

开发者 https://www.devze.com 2023-02-14 04:35 出处:网络
I want to get the source code of a webpage. I am using HttpConnection following is my code.. HttpConnection c = null;

I want to get the source code of a webpage. I am using HttpConnection following is my code..

HttpConnection c = null;
         InputStream dis = null;
         StringBuffer raw = new StringBuffer();
         try {

                c = (HttpConnection)Connector.open(txtUrl.getText().toString());

             int len = 0;
             int size = 0;
             dis = c.op开发者_Go百科enInputStream();
             byte[] data = new byte[256];
             while ( -1 != (len = dis.read(data)) ){

                 raw.append(new String(data, 0, len));
             size += len;    

             }
             System.out.println("Html source"+raw.toString());

         }  catch (IOException e) {
                // TODO Auto-generated catch block
             System.out.println("Exception " +e);
            }
         finally {
             if (dis != null)
                try {
                    dis.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    System.out.println("Exception " +e);
                }
             if (c != null)
                try {
                    c.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    System.out.println("Exception " +e);
                }
         }

At this line dis = c.openInputStream(); i am getting error as source not found - datagramProtocol(ConnectionBase).receive(Datagram). Where I am going wrong please correct me..


You should probably read the API documentation for javax.microedition.io.HttpConnection and implement your input routine as recommended there.

0

精彩评论

暂无评论...
验证码 换一张
取 消