在Android模拟器中设置HTTP连接并获取响应

时间:2011-09-14 11:47:50

标签: android http android-emulator

我有一个Android应用程序,它解析HTML内容并显示所需的标记。 它适用于硬编码的HTML代码。

但是当我为URL设置HTTP连接时,它在模拟器中不起作用。

让我知道如何在android中设置HTTP连接,并在模拟器中查看响应。

我想将该响应作为解析器的输入。

我希望它在Emulator中实现并解析。

我得到的错误是

Exception in thread "main" java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.<init>(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at java.net.URL.openStream(Unknown Source)
    at com.ltil.HtmlContentParser.main(HtmlContentParser.java:31)

1 个答案:

答案 0 :(得分:0)

使用选项-http-proxy <proxy>启动模拟器可以指定代理