1

These days I create the wap. I find a problem that if I set an agency it can connect. It can not connect if it does not set agency. But before this it must be set agency to connect.

The error is:

01-23 11:04:41.400: W/System.err(9328): java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 80) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused)
01-23 11:04:41.400: W/System.err(9328):     at libcore.io.IoBridge.isConnected(IoBridge.java:214)
01-23 11:04:41.410: W/System.err(9328):     at libcore.io.IoBridge.connectErrno(IoBridge.java:152)
01-23 11:04:41.410: W/System.err(9328):     at libcore.io.IoBridge.connect(IoBridge.java:112)
01-23 11:04:41.410: W/System.err(9328):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
01-23 11:04:41.410: W/System.err(9328):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
01-23 11:04:41.410: W/System.err(9328):     at java.net.Socket.connect(Socket.java:872)
01-23 11:04:41.410: W/System.err(9328):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:77)
01-23 11:04:41.410: W/System.err(9328):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
01-23 11:04:41.410: W/System.err(9328):  at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
01-23 11:04:41.410: W/System.err(9328):     at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
01-23 11:04:41.410: W/System.err(9328):     at libcore.net.http.HttpConnection.connect(HttpConnection.java:99)
01-23 11:04:41.410: W/System.err(9328):     at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
01-23 11:04:41.410: W/System.err(9328):     at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
01-23 11:04:41.410: W/System.err(9328):     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
01-23 11:04:41.410: W/System.err(9328):     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
01-23 11:04:41.410: W/System.err(9328):  at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
01-23 11:04:41.410: W/System.err(9328):  at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:188)

It has the error in HttpURLConnection 的getOutputStream() method.

It only has the exception when setting the agency. Who meet the same problem?

DaringLi
  • 409
  • 2
  • 6
  • 16

1 Answers1

1

It looks like you're making a request to localhost (127.0.0.1)

This won't work when running on the phone or emulator as the phone/emu doesn't have a web browser serving on port 80.

Serve your webpage from a publicly accessible address and replace your http://localhost or http://127.0.0.1 with the publicly accessible addresses.

If you need to load an html file from the phone don't use the HTTP Classes, use the File classes.

darryn.ten
  • 6,784
  • 3
  • 47
  • 65