在Android中,我有多个线程,使用HTML
执行Jsoup
解析
我的连接代码是:
Jsoup.connect(url).userAgent(this.userAgent).timeout(10 * 1000).get();
其中this.userAgent
等于最新的Mozilla用户代理 - "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1"
。
现在,当我指定10000ms时,为什么我得到这个SocketTimeoutException
参数为7000ms?
此外,我尝试将超时设置为无限timeout(0)
,我仍然得到此Exception
。
logcat的:
05-11 13:49:45.582 11796-12561/com.dl.master.lyrics.lyricsmaster W/System.err: java.net.SocketTimeoutException: failed to connect to www.songlyrics.com/23.252.119.106 (port 80) after 7000ms
05-11 13:49:45.582 11796-12561/com.dl.master.lyrics.lyricsmaster W/System.err: at libcore.io.IoBridge.connectErrno(IoBridge.java:169)
05-11 13:49:45.583 11796-12561/com.dl.master.lyrics.lyricsmaster W/System.err: at libcore.io.IoBridge.connect(IoBridge.java:122)
05-11 13:49:45.583 11796-12561/com.dl.master.lyrics.lyricsmaster W/System.err: at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
05-11 13:49:45.583 11796-12561/com.dl.master.lyrics.lyricsmaster W/System.err: at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
05-11 13:49:45.583 11796-12561/com.dl.master.lyrics.lyricsmaster W/System.err: at java.net.Socket.connect(Socket.java:882)
05-11 13:49:45.583 11796-12561/com.dl.master.lyrics.lyricsmaster W/System.err: at com.android.okhttp.internal.Platform.connectSocket(Platform.java:139)
05-11 13:49:45.583 11796-12561/com.dl.master.lyrics.lyricsmaster W/System.err: at com.android.okhttp.Connection.connect(Connection.java:148)
05-11 13:49:45.583 11796-12561/com.dl.master.lyrics.lyricsmaster W/System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:276)
05-11 13:49:45.583 11796-12561/com.dl.master.lyrics.lyricsmaster W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
05-11 13:49:45.583 11796-12561/com.dl.master.lyrics.lyricsmaster W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:373)
05-11 13:49:45.583 11796-12561/com.dl.master.lyrics.lyricsmaster W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
05-11 13:49:45.583 11796-12561/com.dl.master.lyrics.lyricsmaster W/System.err: at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:512)
05-11 13:49:45.583 11796-12561/com.dl.master.lyrics.lyricsmaster W/System.err: at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:493)
05-11 13:49:45.583 11796-12561/com.dl.master.lyrics.lyricsmaster W/System.err: at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:205)
05-11 13:49:45.583 11796-12561/com.dl.master.lyrics.lyricsmaster W/System.err: at org.jsoup.helper.HttpConnection.get(HttpConnection.java:194)
05-11 13:49:45.583 11796-12561/com.dl.master.lyrics.lyricsmaster W/System.err: at com.dl.master.lyrics.lyricsmaster.GetSongLyricsDotComResults.getParsedDocument(GetSongLyricsDotComResults.java:183)
05-11 13:49:45.583 11796-12561/com.dl.master.lyrics.lyricsmaster W/System.err: at com.dl.master.lyrics.lyricsmaster.GetSongLyricsDotComResults.getSongLyricsDotComResults(GetSongLyricsDotComResults.java:87)
05-11 13:49:45.583 11796-12561/com.dl.master.lyrics.lyricsmaster W/System.err: at com.dl.master.lyrics.lyricsmaster.GetSongLyricsDotComResults.run(GetSongLyricsDotComResults.java:42)
getParsedDocument()
正在执行我的Jsoup
连接。
修改: 只留下不匹配的ms。
为什么即使我将超时设置为无限,我也会得到SocketTimeoutException
?
修改#2 :
要说我长时间使用Jsoup
API
而不是用户UserAgent
或Timeout
,我决定添加它们。在我将UserAgent
和Timeout
添加到我的连接方法后,问题就开始出现了。
答案 0 :(得分:1)
我有多线程使用Jsoup执行HTML解析。
后,问题就开始出现了
(...)
添加UserAgent
和Timeout
根本原因可能不是来自添加UserAgent
和Timeout
这一事实。
检查
答案 1 :(得分:0)
我连接的 Wifi网络没有互联网,所以我接受了此例外。然后,我连接到了另一个具有Internet的网络,然后得到了服务器的响应。