正在建立连接,但无法从Web服务检索内容

时间:2012-01-14 22:45:27

标签: blackberry

public class ConsumeFactoryThread extends Thread {
    private String url;
    private HttpConnection httpConn;
    private InputStream is;
    private CustomMainScreen m;
    private JSONArray array;

    public ConsumeFactoryThread(String url, CustomMainScreen m){
        System.out.println("Connection begin!");
        this.url = url;
        this.m = m;
    }

    public void finished(){
        m.onFinish(array);


    }

    public void run(){

        myConnectionFactory connFact = new myConnectionFactory();
        ConnectionDescriptor connDesc;

        connDesc = connFact.getConnection(url);
        System.out.println("Connection factory!");
        if(connDesc != null)
        {
            System.out.println("Connection not null!");
            httpConn = (HttpConnection) connDesc.getConnection();
            is = null;



            try
            {
                final int iResponseCode = httpConn.getResponseCode();
                UiApplication.getUiApplication().invokeLater(new Runnable()
                {

                    public void run()
                    {
                        System.out.println("Connection in run!");
                         // Get InputConnection and read the server's response
                        InputConnection inputConn = (InputConnection) httpConn;
                        try {
                            is = inputConn.openInputStream();
                            System.out.println("Connection got inputstream!");
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        byte[] data = null;
                        try {
                            data = IOUtilities.streamToBytes(is);
                            System.out.println("Connection got data!");
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }



                        String result = new String(data);
                        System.out.println("Connection Data: "+result);
                        try {
                            array = new JSONArray(result);

                            //finished();

                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }


                    }

                });
            }
            catch(IOException e)
            {
                System.err.println("Caught IOException: " + e.getMessage());
            }
        }

    }

}

我正在使用黑莓火炬9800模拟器和硬件设备进行测试。 在模拟器中,我无法通过wifi检索数据,即使找到了与wifi的连接。它在移动网络启用时有效。

现在,当我用Twitter api替换我的Web服务时,无论传输类型如何,我都会获得数据。我尝试添加; deviceside = false到我的网址,但没有。它不是https或任何东西。

我只想访问我的网络服务!我对这个mds,bis,bes,bis_b垃圾一无所知。

编辑:

哎呀。我意识到它可能是我的网站。不使用网络服务只是检索页面www.example.com,我什么都没得到。但是,google.com或我使用的任何其他网站都会检索html。我错过了标题!?!

1 个答案:

答案 0 :(得分:0)

尝试将;interface=wifi附加到您网址的末尾,这会强制模拟器使用您的PC网络连接模拟的Wi-Fi连接。

您需要在模拟器上设置Wi-Fi,然后转到Manage Connections->Set Up Wi-Fi Network,然后连接到Default WLAN Network