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 4574534
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:56:10+00:00 2026-05-21T19:56:10+00:00

I have an AsyncTask in my application that creates a HttpURLConnection. Next, it calls

  • 0

I have an AsyncTask in my application that creates a HttpURLConnection. Next, it calls getOutputStream(), writes some bytes, flushes and closes. Then it calls getResponseCode(), and getInputStream(). If I need to post code, I can, but thought I’d keep the question small.

When I run this the first time, I get a 200 response code, and I get the correct input stream.

When I run this a second to fifth time, I get a new thread (viewable in the DDMS view), and I receive a 500 response code, and an IOException when getting the input stream.

When I call this a sixth time or more, no new threads are created, and I still get the 500 response code and the IOException.

What can I look for here? It always works one time and never again. Has anyone else seen this? I’m completely stumped.

Here’s MINIMAL code (I removed try/catch, variable declarations, app specific stuff, etc):

   protected String doInBackground(String... params)
   {
     connectURL = new URL(sWebPath);
     conn = (HttpURLConnection)connectURL.openConnection();

     conn.setDoInput(true);
     conn.setDoOutput(true);
     conn.setUseCaches(false);
     conn.setConnectTimeout(10000);

     conn.setRequestMethod("POST");

     conn.setRequestProperty("User-Agent", "MyAppAgent");
     conn.setRequestProperty("Connection", "Keep-Alive");
     conn.setRequestProperty("Content-Type", "application/soap+xml; charset=utf-8");

     // Setup my post as a string s.

     conn.setRequestProperty("Content-Length", String.valueOf(s.length()));

     conn.connect();
     DataOutputStream dataStream = new DataOutputStream(conn.getOutputStream());
     dataStream.writeBytes(s);

     dataStream.flush();
     dataStream.close();
     dataStream = null;

     // 200 1st time only, 500 after that.
     responseCode = conn.getResponseCode();

     // Works 1st time only, IO error after that
     DataInputStream dis = new DataInputStream(conn.getInputStream());
     byte[] data = new byte[16384];
     int len = dis.read(data, 0, 16384);

     dis.close();
     conn.disconnect();

     response = new String(data, 0, len);

     // do whatever with my response
  }

  @Override
  protected void onPostExecute(String result)
  {
     super.onPostExecute(result);

     // Now I call a Toast message on the original context used to 
     // create this AsyncTask.
  } 

  // The onClickListener of a button calls this AsyncTask (TierRequest class) with only two lines
  TierRequest t = new TierRequest(WhateverMyCurrentActivityIs.this);
  t.execute(A_Constant_Indicating_The_Type_Of_Post);
  • 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-21T19:56:11+00:00Added an answer on May 21, 2026 at 7:56 pm

    This really feels like a problem on the server (code 500 is almost universally used to indicate some sort of problem in the server side code, although it could be a problem with the web server itself).

    Do you control the server code? Are you possibly opening a file and not closing it, so that additional calls may run into “access denied” or “file already open” errors?

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

Sidebar

Related Questions

I have an application that uses AsyncTasks to make REST calls to a server.
I have an application that uses AsyncTasks to make calls to a REST server.
I have an android application that parses some HTML, downloads an image, and displays
I have an asynctask that reads data from a device and then I want
I have an application that does some long calculations, and I would like to
My goal is to have an AsyncTask that can execute multiple times (one task
I have a class that extends AsyncTask. In the doInBackground() method, I connect to
I have some problem with Android AsyncTask. There is an Activity which contains some
I have an Activity class which has an attribute that references an AsyncTask instance
I have an application that is performing HTTP Requests (specifically calling the FogBugz API)

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.