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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:52:04+00:00 2026-06-02T01:52:04+00:00

I have PHP webservices and i want to call it throw AsyncTask ..at this

  • 0

I have PHP webservices and i want to call it throw AsyncTask ..at this stage i have no problem..my problem is that i want to make one class extends AsyncTask and pass to it the uri of the webservices to call it many times in many activities but i don’t know how to do this and call the asynctask .. any help..
Thank you

this is what i have tried to do but it is not working

    public class GetNetworkData  extends AsyncTask<String, Void, String>{

    String uri;
    private OnPostExecuteListener  mPostExecuteListener = null;
    public static interface OnPostExecuteListener
    {

                void onPostExecute(String result);

            }


    GetNetworkData(
            String Url,
            OnPostExecuteListener postExecuteListener) throws Exception {

            uri = Url;
            mPostExecuteListener = postExecuteListener;
            if (mPostExecuteListener == null)
                throw new Exception("Param cannot be null.");
        }

    @Override
    protected String  doInBackground(String... params) {
        // TODO Auto-generated method stub  

        JSONObject param=null;
      String result = null;
      HttpClient httpClient = new DefaultHttpClient();
            HttpHost httpHost = new HttpHost("192.168.3.111",80);  
            HttpPost httpPost = new HttpPost(uri);
            httpPost.addHeader("Content-Type", "application/json; charset=utf-8");


            try
            {
                //HttpEntity bodyEntity = new StringEntity(param.toString(), "utf8");
                //httpPost.setEntity(bodyEntity);
                HttpResponse response = httpClient.execute(httpPost);
                HttpEntity entity = response.getEntity();

                if (entity != null) {
                    InputStream instream = entity.getContent();
                    BufferedReader reader = new BufferedReader(
                         new InputStreamReader(instream));
                    StringBuilder sb = new StringBuilder();


                    String line = null;
                    while ((line = reader.readLine()) != null)
                        sb.append(line + "\n");


                    result = sb.toString();
                    instream.close();      
                }

                }
                catch (Exception e) {
                    // TODO: handle exception
                }

        return result;
    }   

    @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub
         if (mPostExecuteListener != null)
         {
          try {
                    JSONObject json = new JSONObject(result);
                    mPostExecuteListener.onPostExecute(result);
                } catch (JSONException e){
                    e.printStackTrace();
                }
            }           
    }  
}
  • 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-02T01:52:06+00:00Added an answer on June 2, 2026 at 1:52 am

    Create instances of GetNetworkData class wherever and whenever you need. If the Url and postExecuteListener parameters are the same across all the invocations, you could think of a wrapper class that will save these in instance variables and create the GetNetworkData objects on demand.

    The code for using GetNetworkData would be:

    String url = "http://....";
    GetNetworkData.OnPostExecuteListener listener = new GetNetworkData.OnPostExecuteListener() {
        @Override
        public void onPostExecute(String result) {
            Log.d("AsyncTask", "onPostExecute: " + result); 
            //Do what you want to do after the task is complete
        }
    };
    
    GetNetworkData task = new GetNetworkData(url, listener);
    task.execute();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to consume a WCF WebServices but the WSDL contains bindings that PHP
I have PHP scrip that goes like this: if ($cost_frm < $cost){ echo <script
I have a few php pages that might want to access the database and
I have a PHP web application developed using symfony framework. I want to call
I have a PHP webservice that returns an XML output, and one of the
I want to make a call to a webservice of which I only have
i have one webservices(in PHP) i need to parse it so simply i need
Im currently posting some data to a php webservice using a class that extends
I have a RPC encoded PHP webservice that returns a simple soap envelope with
I have created a function in PHP that calls a webservice and parses through

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.