2013-08-18 3 views
2

현재 booklooker.de에서 최저 가격의 도서 목록을 제공하는 programm를 작성하려고합니다. 사이트 자체는 https를 사용하며 그것이 문제라고 생각합니다.자바에서 https-URL을 읽는 것

코드 :

import java.io.*; 
import java.net.*; 
import javax.net.ssl.HttpsURLConnection; 

public class Booklooker { 
    public static void main(String[] args) throws Exception{ 
     // TODO Auto-generated method stub 
     BufferedReader in = new BufferedReader(new FileReader("list.txt")); 
     PrintStream out = new PrintStream(new FileOutputStream(new File("result.txt"))); 

     String book = ""; 
     while((book = in.readLine()) != null){ 
      book.replace(' ', '+').replace("ä", "%E4").replace("ö", "%F6").replace("ü", "%FC").replace("ß", "%DF"); 
      URL link = new URL("https://secure.booklooker.de/app/result.php?sortOrder=preis_total&setMediaType=0&titel="+book); 
      HttpsURLConnection con = (HttpsURLConnection)link.openConnection(); 
      BufferedReader site = new BufferedReader(new InputStreamReader(con.getInputStream())); 
      while(true){ 
       String line = ""; 
       if((line = site.readLine()) == null){ 
        out.print("Error\n"); 
        break; 
       } 
       else if(line.indexOf(" €") != -1){ 
        int index = line.indexOf(" €"); 
        double price = Double.parseDouble(line.substring(index-5, index).trim().replace(',', '.')); 
        index   = line.indexOf(" €", index+12); 
        double postage = Double.parseDouble(line.substring(index-5, index).trim().replace(',', '.')); 
        out.print(price+postage+"\n"); 
        break; 
       } 
      } 
      site.close(); 
     } 
     in.close(); 
     out.close(); 
     System.out.println("Finished."); 
    } 
} 

그리고 오류가 다시 주어진 :

Exception in thread "main" java.io.IOException: Invalid Http response 
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) 
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source) 
    at Booklooker.main(Booklooker.java:16) 

내가 잘못 정확히 무슨 일이 일어나고 있는지 알고 있지만, HttpsURLConnection에 문제가있는 것 같습니다하지 않습니다. 아무도 아이디어가 있니?

답변

0

귀하의 URL은 유효하지 않습니다. 후행 앰퍼샌드를 제거하십시오. HTTPS 또는 SSL 문제는 여기에 없으며 다른 예외가있을 수 있습니다.

+0

아니요, URL은 유효하며 후행 앰퍼샌드가 포함되거나 포함되지 않습니다.; 이 경우 오류 보고서에 HttpsURLConnectionImpl.getInputStream (알 수없는 소스)에서 잘못된 Http 응답이 표시되는 이유는 무엇입니까? – njcasdewdwas