0

Hi guys I am working in a download manager projetct.

I was testing some link and is working fine, however I found a problem

This two links below was from emupardise, I will be using then only to show my point.

If I use this code:

     String GameLink = "http://www.emuparadise.me/roms/get-download.php?gid=43269&token=2f91d51fcd8b90cec75193ffd592f07c&mirror_available=true";
//    String GameLink = "http://www.emuparadise.me/roms/get-download.php?gid=43270&token=a6f395885bea3bbef73d972804d2cbdb&mirror_available=true";


             try {


URL url = new URL(GameLink);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestProperty("Host" ,"www.emuparadise.me");
con.setRequestProperty("Accept" ,"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
con.setRequestProperty("Accept-Encoding" ,"gzip, deflate");
con.setRequestProperty("Referer" ,"www.emuparadise.me");
con.setRequestProperty("Connection" ,"keep-alive");



   System.out.println("Server answer :"+ con.getResponseCode());

con.connect();
InputStream is = con.getInputStream();
System.out.println(con.getURL().toString()+"\n");

is.close();

        } catch (IOException ex) {
            Logger.getLogger(Question.class.getName()).log(Level.SEVERE, null, ex);
        }

In the first I get:

"Server answer :200" (Like I want), however using the second link I get:

"Server answer :-1" and then I get the error: java.io.IOException: Invalid Http response

I already checked the header in both pages and they are the same, besides both links work in Internet Download Manager, can anyone please provide me a solution?

Thanks very much for your time

Lucas
  • 3
  • 1

1 Answers1

1

According to the javadoc for the getResponseCode() method:

"Returns -1 if no code can be discerned from the response (i.e., the response is not valid HTTP)."

It is most likely a problem at the server end. Instead of responding to your request with a proper HTTP response, the server might be sending garbage ... or simply closing the connection. Or it could be an intermediary doing this; i.e. a proxy or reverse proxy.


You should probably try to use a packet monitor or something to determine what is actually in the server's response. Or just report it to the site maintainers.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216