I am executing the following code and always get an EOFException in urlConnection.getInputStream(). I know that the webserver is not returning proper headers, but if I use the same url in a web browser I get the expected content back.
URL url1;
try
{
url1 = new URL("http://63.255.173.242/get_public_tbl.cgi?A=1");
HttpURLConnection urlConnection = (HttpURLConnection) url1.openConnection();
try
{
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
readStream(in);
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
urlConnection.disconnect();
}
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
Any ideas?
Edit 1:
I thought I was on to a possible solution. I found that using Android 2.3 I can read the response by calling getHeaderFields() (even though there is no header), but if I use Android 4.1 getHeaderFields() returns null. Any ideas?
url1 = new URL("http://63.255.173.242/get_public_tbl.cgi?A=1");
URLConnection urlConnection = url1.openConnection();
Map<String, List<String>> fields = urlConnection.getHeaderFields();