您好,登錄后才能下訂單哦!
當你啟動Tomcat后,在瀏覽器中輸入http://127.0.1.1:8080/xxx.xx,你會發現你可以找打你要找的東西。但是當你在Eclipse中運行測試代碼后,JUnit會一直報出這樣的錯誤:
java.net.ConnectException: failed to connect to /127.0.1.1 (port 8080) after 5000ms: isConnected failed: ECONNREFUSED (Connection refused)
at libcore.io.IoBridge.isConnected(IoBridge.java:223)
at libcore.io.IoBridge.connectErrno(IoBridge.java:161)
at libcore.io.IoBridge.connect(IoBridge.java:112)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
at java.net.Socket.connect(Socket.java:843)
at com.android.okhttp.internal.Platform.connectSocket(Platform.java:131)
at com.android.okhttp.Connection.connect(Connection.java:101)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:294)
at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:179)
此時,你的第一反應可能是某出代碼有問題或者是清單文件中某個權限忘加了,其實不是這樣的。原來模擬器默認把127.0.0.1和localhost當做本身了,在模擬器上可以用10.0.2.2代替127.0.0.1和localhost,另外如果是在局域網環境可以用 192.168.0.x或者192.168.1.x(根據具體配置)連接本機,這樣應該就不會報錯了。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。