2016-04-03 14 views
0

Json'u almak için bu kodu kullanıyorum, ancak FileNotFoundException döndürüyor. Tarayıcıda çalışır. Java'da neden çalışmadığını anlamıyorum ... HttpsUrlConnection'ı kullanmayı deniyorum, ancak sonuç değişmiyor.Google kitaplar filenotfound java

String url = "https://www.googleapis.com/books/v1/volumes"; 
    HashMap<String, String> params = new HashMap<String, String>(); 
    params.put("q", "isbn:9785090212779"); 
    StringBuilder postData = new StringBuilder(); 
    if (params != null) 
     for (Map.Entry<String, String> param : params.entrySet()) { 
      if (postData.length() != 0) postData.append('&'); 
      postData.append(URLEncoder.encode(param.getKey(), "UTF-8")); 
      postData.append('='); 
      postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8")); 
     } 
    byte[] postDataBytes = postData.toString().getBytes("UTF-8"); 

    HttpsURLConnection urlc = (HttpsURLConnection) 
      new URL(url).openConnection(); 
    urlc.setDoOutput(true); 
    urlc.setRequestMethod("GET"); 
    urlc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
    urlc.setRequestProperty("charset", "UTF-8"); 
    urlc.setRequestProperty("Content-Length", Integer.toString(postDataBytes.length)); 
    DataOutputStream wr; 
    wr = new DataOutputStream(urlc.getOutputStream()); 
    wr.write(postDataBytes); 
    wr.flush(); 
    wr.close(); 


    urlc.setConnectTimeout(2000); 
    DataInputStream is = new DataInputStream(urlc.getInputStream()); 
    BufferedReader br = new BufferedReader(new InputStreamReader(is)); 
    StringBuilder sb = new StringBuilder(); 
    String line; 
    while ((line = br.readLine()) != null) { 
     sb.append(line); 
    } 
    br.close(); 
    urlc.disconnect(); 
    System.out.println(sb.toString()); 

İstisna: https://console.developers.google.com/apis/

:

Exception in thread "main" java.io.FileNotFoundException: https://www.googleapis.com/books/v1/volumes 
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1836) 
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441) 
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254) 
    at Main.main(Main.java:43) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) 
+0

Bağlantıda belirtilen uygun değişiklikleri yapabilirsiniz: http://www.mkyong.com/java/how-to-send-http-request-getpost-in-java/ – AbhishekAsh

+0

Test 2 - Http POST isteği gönder "Ana" java.io.FileNotFoundException dizesinde istisna: https://selfsolve.apple.com/wcResults.do \t sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Yerel –

cevap

0

Google Kitaplar sadece istek GET kullanın Burada anahtarınızı almak query.You fpr Google Api-anahtar eklemek zorunda

0

Sonunda bağlantınızın şu şekilde olması gerekir:

https://www.googleapis.com/books/v1/volumes?q=isbn=9783446440739&key=HERE_IS_YOUR_API_KEY 
İlgili konular