E
epicwinter
I am making a simple https request and reading in the response. When I
do so I am always getting a Premature EOF exception from this
particular site which is the one I need to work with. I will be
receiving a mix of text and binary files in the response. So somehow I
need to interpret whether i am getting a binary file or a simple text
response. No matter what the response is I seem to be getting this
error though. I don't think this is typical but when I try the same
excercise using curl I receive no error, so I assume it is a personal
code problem. This is always how I have read the response stream in
the past, with success. What am I doing wrong?
Below is a functioning test that will reproduce my error, it is just
receiving a text response and outputs all of the response. As you can
see it just pings the web page and displays the html contained in the
response in full and then throws the Premature EOF exception.
import java.net.*;
import java.io.*;
public class Test
{
public static void main(String [] arstring)
{
try
{
URL url1 =new java.net.URL("https",
"cert.access.webmd.com", 443, "/ITS/post.aspx");
URLConnection connection = url1.openConnection();
connection.setUseCaches( false );
connection.setDoOutput( true );
connection.setDoInput( true );
InputStream inputStream = connection.getInputStream();
InputStreamReader isr = new InputStreamReader(inputStream
);
BufferedReader br = new BufferedReader(isr);
int c = -1;
while ((c= br.read()) >=0)
{
System.err.print((char)c);
}
br.close();
isr.close();
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
}
do so I am always getting a Premature EOF exception from this
particular site which is the one I need to work with. I will be
receiving a mix of text and binary files in the response. So somehow I
need to interpret whether i am getting a binary file or a simple text
response. No matter what the response is I seem to be getting this
error though. I don't think this is typical but when I try the same
excercise using curl I receive no error, so I assume it is a personal
code problem. This is always how I have read the response stream in
the past, with success. What am I doing wrong?
Below is a functioning test that will reproduce my error, it is just
receiving a text response and outputs all of the response. As you can
see it just pings the web page and displays the html contained in the
response in full and then throws the Premature EOF exception.
import java.net.*;
import java.io.*;
public class Test
{
public static void main(String [] arstring)
{
try
{
URL url1 =new java.net.URL("https",
"cert.access.webmd.com", 443, "/ITS/post.aspx");
URLConnection connection = url1.openConnection();
connection.setUseCaches( false );
connection.setDoOutput( true );
connection.setDoInput( true );
InputStream inputStream = connection.getInputStream();
InputStreamReader isr = new InputStreamReader(inputStream
);
BufferedReader br = new BufferedReader(isr);
int c = -1;
while ((c= br.read()) >=0)
{
System.err.print((char)c);
}
br.close();
isr.close();
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
}