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

  • SEARCH
  • Home
  • 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 9139787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:25:59+00:00 2026-06-17T09:25:59+00:00

I have a method (below) to get data from web services in my android

  • 0

I have a method (below) to get data from web services in my android program. It works fine with Android 2.2. But in 4.x it throws an exception with message “Error Requesting API”. Not sure which part is causing the exception in my code and why only in 4.x Can someone give me some pointers?

        public static synchronized String performHTTPRequest(HttpUriRequest request)
                throws ApiException, ParseException, IOException {
            HttpClientWrapper cli=new HttpClientWrapper();
            HttpClient client;
            try {
                client=cli.getClient();
                HttpResponse response = client.execute(request);
                // Check if server response is valid
                StatusLine status = response.getStatusLine() ;

            if (status.getStatusCode() != HTTP_STATUS_OK) {
                throw new ApiException("Invalid response from server: " + status.toString());
            }
            return EntityUtils.toString(response.getEntity());
        } catch (MalformedURLException e) {
            throw new Error(e);
        }  catch (Exception cnrce) {
            throw new ApiException("Error requesting API:");
        }
    }
  • 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-06-17T09:25:59+00:00Added an answer on June 17, 2026 at 9:25 am

    In 4.0 or the verions above honeycomb you can not perform any http request on ui thread.
    You need to perform these in asynctask.
    EDIT:
    Documentation

    Code example for asynctask

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Web Api project I have a Get method which returns data from
I have problem with android 4.0.3. I'm using the method below to get local
I have the method below to parse data from the twitter search, strange thing
I have the method below, which in my Blackjack app will get the value
I have a NSURLConnection that gets data from a JSON web service, and everything
I have a doubt regarding downloading data from a web service. One way is
I have use Ajax and jquery for get data from database and send data,
I have a rest web service as below: @GET @Path(/getPersonDetails/{personId}/{validDate}) @Produces(application/xml) public PersonDetail getPersonDetails(@PathParam(personId)
I have a POST ASP.Net Web Api method adapted from A guide to asynchronous
I have designed a web service application and fetch app's data from my server

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.