Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6846269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:36:03+00:00 2026-05-27T00:36:03+00:00

I am trying to download some JSON from the google book API. The URL

  • 0

I am trying to download some JSON from the google book API.

The URL and API-Key I’m using seems to work becuase i can fetch it manually with a browser. I call this class and use this function passing it a usable URL. I’ve tried post and get(You can see where I’ve commited out the other.

While Im debugging I can watch it start the download process or it seems to but it always comes returns null. It seems like it should be working. any ideas of what might be happening? A permission or something.(Already added INTERNET PERMISSION)

public static class JSONFunctions2 {
        public static JSONObject getJSONfromURL(String url){

                /*//initialize*/
            InputStream is = null;
                String result = "";
            JSONObject jArray = null;

            //http post
            try{
                 HttpClient httpclient = new DefaultHttpClient();
                 HttpPost httppost = new HttpPost(url);
                 HttpResponse response = httpclient.execute(httppost);
                 HttpEntity entity = response.getEntity();
                 is = entity.getContent();

                     }catch(Exception e){
                  Log.e("log_tag", "Error in http connection "+e.toString());
                     }

                 //convert response to string
                 try{
                       BufferedReader reader = new BufferedReader(new   InputStreamReader(is,"iso-8859-1"),8);
                   StringBuilder sb = new StringBuilder();
                   String line = null;
                   while ((line = reader.readLine()) != null) {
                      sb.append(line + "\n");
                   }
                   is.close();
                   result=sb.toString();
                   }catch(Exception e){
                      Log.e("log_tag", "Error converting result "+e.toString());
                   }

                   /*DefaultHttpClient client = new DefaultHttpClient();
                   HttpGet getRequest = new HttpGet(url);
                   HttpResponse getResponse;
                   getResponse = client.execute(getRequest);
                   HttpEntity getResponseEntity = getResponse.getEntity();
                   if (getResponseEntity != null) {
                     result= EntityUtils.toString(getResponseEntity);
                    }*/

                    /*//try parse the string to a JSON object*/
                    try{
                            jArray = new JSONObject(result);
                    }catch(JSONException e){
                        Log.e("log_tag", "Error parsing data "+e.toString());
                    }

                    return jArray;
                }
    }

I guess this is the logcat (Im somewhat new to this, some of it on the top might because I switched my phone from wifi to reg. Phone Data)

11-06 23:02:23.716: ERROR/InputDispatcher(159): channel '4081c258 com.buddy/com.BuddyListActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x8
11-06 23:02:23.716: ERROR/InputDispatcher(159): channel '4081c258 com.buddy/com.BuddyListActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
11-06 23:03:36.616: ERROR/log_tag(4116): Error in http connection javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
11-06 23:03:36.616: ERROR/log_tag(4116): Error converting result java.lang.NullPointerException
11-06 23:04:04.766: ERROR/log_tag(4116): Error parsing data org.json.JSONException: End of input at character 0 of
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:36:03+00:00Added an answer on May 27, 2026 at 12:36 am

    Ok, after some informative input and research I’ve found a connection method that connects to the google book api and retrieves the JSON. The connection does use the TrustEveryOne class but it does retrieve the JSON. I’ll have to work on certificate auth later, app isnt distributed yet.

    public static JSONObject getJSONfromURL(String urlpass) throws ParseException, IOException{
    
        /*//initialize*/
        InputStream is = null;
        String result = "";
        JSONObject jArray = null;
        int response = -1;
    
        URL url = new URL(urlpass);
        TrustEveryone.trustEveryone();
        URLConnection conn = url.openConnection();
    
        if (!(conn instanceof HttpURLConnection))                     
            throw new IOException("Not an HTTP connection");        
        try{
            HttpURLConnection httpConn = (HttpURLConnection) conn;
            httpConn.setAllowUserInteraction(false);
            httpConn.setInstanceFollowRedirects(true);
            httpConn.setRequestMethod("GET");
            httpConn.connect();
            response = httpConn.getResponseCode();                 
            if (response == HttpURLConnection.HTTP_OK) {
                is = httpConn.getInputStream();                                 
            }                     
        }
        catch (Exception ex)
        {
            throw new IOException("Error connecting");            
        }
    
        try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            result=sb.toString();
        }catch(Exception e){
            Log.e("log_tag", "Error converting result "+e.toString());
        }
        /*//try parse the string to a JSON object*/
        try{
            jArray = new JSONObject(result);
        }catch(JSONException e){
            Log.e("log_tag", "Error parsing data "+e.toString());
        }
    
        return jArray;    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm, trying to download some Google Analytics data from their API. I can download
I am trying to download the image from the url http://a3.twimg.com/profile_images/414797877/05052008321_bigger.jpg I am using
I'm trying to download some data using pure javascript/html from cross-domain, dropbox to be
Im trying to download share data from a stock exchange using python. The problem
I'm trying to download images (.jpg) from web folder using wget. I want to
I'm trying to use the NAnt <get> task to download some artifacts from our
I am trying to download some data from the reporting services instance on our
I have to download some files from an FTP server. Seems prosaic enough. However,
I'm trying to download an image from a url. The process I wrote works
I'm trying to download imags from a url and then decode them. The problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.