Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting a very general IOException with HttpUrlConnection
    text
    copied!<p>I'm having some problems with HttpUrlConnection, When I run the device (Gingerbread HTC Desire) LogCat displays the very general:</p> <p><code>11-23 14:26:19.394: WARN/System.err(6591): java.io.IOException: Error connecting</code> </p> <p>I've added AsyncTask to try and remedy the problem, but there seems to be no difference. I've shown the full logcat at the bottom, here is the class in question (shortened it up a bit and set the url to google (same results):</p> <pre><code>public class JSoupHelper { private static final String LOGIN_URL = "http://www.google.co.uk"; public JSoupHelper() { new Login().execute(LOGIN_URL); } private class Login extends AsyncTask&lt;String, String, InputStream&gt;{ @Override protected InputStream doInBackground(String... params) { String url = params[0]; Log.d("JSoup-LoginHelper","Starting background AsyncTask on "+url); try { InputStream is = OpenHttpConnection(url); return is; } catch (IOException e) { e.printStackTrace(); } return null; } } private InputStream OpenHttpConnection(String urlString) throws IOException { InputStream in = null; URL url = new URL(urlString); Log.d("JSoup-OHTTPSC","Connecting to "+urlString); try{ HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setInstanceFollowRedirects(true); conn.setDoInput(true); conn.connect(); Log.d("JSoup-OHTTPSC","Connected to "+urlString); int response = conn.getResponseCode(); if (response == HttpsURLConnection.HTTP_OK) { in = conn.getInputStream(); } conn.disconnect(); } catch (Exception ex) { throw new IOException("Error connecting"); } return in; } } </code></pre> <p>LOGCAT:</p> <pre><code>11-23 14:25:59.214: DEBUG/JSoup-LoginHelper(6591): Starting background AsyncTask on http://www.google.co.uk 11-23 14:25:59.234: DEBUG/JSoup-OHTTPSC(6591): Connecting to http://www.google.co.uk ~~~~ 20 secs pass ~~~~ 11-23 14:26:19.394: WARN/System.err(6591): java.io.IOException: Error connecting 11-23 14:26:19.394: WARN/System.err(6591): at com.example.untitled1.JSoupHelper.OpenHttpsConnection(JSoupHelper.java:67) 11-23 14:26:19.394: WARN/System.err(6591): at com.example.untitled1.JSoupHelper.access$100(JSoupHelper.java:12) 11-23 14:26:19.394: WARN/System.err(6591): at com.example.untitled1.JSoupHelper$Login.doInBackground(JSoupHelper.java:40) 11-23 14:26:19.394: WARN/System.err(6591): at com.example.untitled1.JSoupHelper$Login.doInBackground(JSoupHelper.java:34) 11-23 14:26:19.394: WARN/System.err(6591): at android.os.AsyncTask$2.call(AsyncTask.java) 11-23 14:26:19.394: WARN/System.err(6591): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 11-23 14:26:19.394: WARN/System.err(6591): at java.util.concurrent.FutureTask.run(FutureTask.java:138) 11-23 14:26:19.394: WARN/System.err(6591): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 11-23 14:26:19.394: WARN/System.err(6591): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 11-23 14:26:19.394: WARN/System.err(6591): at java.lang.Thread.run(Thread.java:1027) 11-23 14:26:23.077: INFO/htcfs-main(6749): main() </code></pre> <p>My goal here is to actually acquire an InputStream and parse it using JSoup via HttpsUrlConnection, login using post and then save the cookies and sessions variables, then using the cookies I can do some proper scraping of the website and store the results into a Sqlite db... but one step at a time (especially with my lack of debugging skills and general Java skills).</p> <p>Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload