I'm running the following test Java script from the Android HttpURLConnection docs:
URL url = new URL("http://www.android.com/");
HttpURLConnection urlConnection = (HttpURLConnection)
url.openConnection();
urlConnection.connect();
Eclipse (on my Mac) is telling me there's a system error when I run this in the Android Emulator:
01-13 13:44:32.767: WARN/System.err(1382): java.net.SocketException: Permission denied
(Incidentally when I do the equivalent in Objective-C/Cocoa there's no problem at all.)
What is the problem?
The getResponseMessage is a method of Java HttpURLConnection class. This method is used to get response code from HTTP response message. For example, if the response code from a server is HTTP/1.0 200 OK or HTTP/1.0 404 Not Found, it extracts the string OK and Not Found else returns null if HTTP is not valid.
Each instance of HttpURLConnection may be used for one request/response pair. Instances of this class are not thread safe.
HttpsURLConnection extends HttpURLConnection , and your connection is an instance of both. When you call openConnection() the function actually returns an HttpsURLConnection . However, because the https object extends the http one, your connection is still an instance of an HttpURLConnection .
To close the connection, invoke the close() method on either the InputStream or OutputStream object. Doing that may free the network resources associated with the URLConnection instance.
Your application is not allowed to access the network unless it has declared that its going to in the AndroidManifest.xml file, add this inside the <manifest>
element.
<uses-permission android:name="android.permission.INTERNET" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With