private String transportHttpMessage(String message) {
      URL serverurl;
      HttpURLConnection connection;

      try {
        serverurl = new URL(this.ServerUrl);
        connection = (HttpURLConnection) serverurl.openConnection();
        connection.setDefaultUseCaches(false);
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setRequestMethod("POST");
        connection.setRequestProperty("content-type", "application/x-www-form-urlencoded");
      } catch (Exception e) {
        e.printStackTrace();
        return null;
      }

      OutputStreamWriter outstream;
      try {
        outstream = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
        outstream.write(message);
        outstream.flush();
        /*
        PrintWriter writer = new PrintWriter(outstream);
        writer.write(message);
        writer.flush();
        */
        outstream.close();
      } catch (Exception e) {
        e.printStackTrace();
        return null;
      }

      StringBuilder strbuilder = new StringBuilder();
      try {
        InputStreamReader instream = new InputStreamReader(connection.getInputStream(), "UTF-8");
        BufferedReader reader = new BufferedReader(instream);

        String str;
        while ((str = reader.readLine()) != null) strbuilder.append(str + "\r\n");

        instream.close();
      } catch (Exception e) {
        e.printStackTrace();
        return null;
      }

      connection.disconnect();
      return strbuilder.toString();
    }
  public boolean request(Object soaprequest) {
    if (!checkSoapMemberVariable()) return false;

    ServiceRequest req =
        new ServiceRequest(
            this.ServerUrl,
            this.SoapAction,
            this.NameSpace,
            this.MethodName,
            this.SoapVersion,
            this.DotNet,
            (SoapObject) soaprequest);
    Thread thread = new Thread(req);

    try {
      thread.start();
      thread.join();
    } catch (Exception e) {
      this.Response = null;
      e.printStackTrace();
      return false;
    }

    this.Response = req.getResponse();
    if (this.Response == null) return false;
    return true;
  }
 @Override
 protected Void doInBackground(Integer... params) {
   try {
     Log.v("drive", "2exit");
     if (driver.drive2Exit() == false) {
       Toast.makeText(StatePlay.this, "Fuel Empty", Toast.LENGTH_SHORT).show();
       Intent i = new Intent(StatePlay.this, AMazeActivity.class);
       startActivity(i);
     }
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return (null);
 }
    public void run() {
      Log.d("SOAP_REQ:NameSpace", this.NameSpace);
      Log.d("SOAP_REQ:MethodName", this.MethodName);
      if (this.SoapRequest == null) {
        this.SoapRequest = new SoapObject(this.NameSpace, this.MethodName);
      }
      Log.d("SOAP_SoapRequest*", this.SoapRequest.toString());

      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(this.SoapVersion);
      envelope.dotNet = this.DotNet;
      envelope.implicitTypes = true;
      envelope.setAddAdornments(false);
      // envelope.avoidExceptionForUnknownProperty = true;
      envelope.setOutputSoapObject(this.SoapRequest);

      Log.d("SOAP_REQ:ServerUrl", this.ServerUrl);
      Log.d("SOAP_REQ:SoapAction", this.SoapAction);
      HttpTransportSE httptransport = new HttpTransportSE(this.ServerUrl);
      httptransport.debug = true;

      try {
        httptransport.call(this.SoapAction, envelope);
        Log.d("SOAP_REQ:Dump*", httptransport.requestDump);
        this.Response = envelope.getResponse().toString();
        if (this.Response != null) Log.i("SOAP_RSP(ksoap2)", this.Response);
      } catch (Exception e) {
        this.Response = null;
        e.printStackTrace();
      }

      // testing...
      if (this.Response == null && httptransport.requestDump != null) {
        this.Response = transportHttpMessage(httptransport.requestDump);
        if (this.Response != null) Log.i("SOAP_RSP(javanet)", this.Response);
      }
    }
    protected Boolean doInBackground(ArrayList... params) {
      download_photos.this.runOnUiThread(
          new Runnable() {
            public void run() {
              mtext.setText(
                  getText(R.string.download_textview_message_1) + " " + path.toString() + ". ");
            }
          });

      if (resume_file.exists()) {
        initial_value = readProgress()[0];
      } else {
        initial_value = 1;
      }

      for (int i = initial_value - 1; i < links.size(); i++) {
        // asynctask expects more than one ArrayList<String> item, but we are sending only one,
        // which is params[0]
        Uri imageuri = Uri.parse(params[0].get(i).toString());
        URL imageurl = null;
        HttpURLConnection connection = null;
        total_files_to_download = links.size();
        completed_downloads = i + 1;
        try {
          imageurl = new URL(params[0].get(i).toString());
          connection = (HttpURLConnection) imageurl.openConnection();
          connection.connect();
        } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

        // extracts the real file name of the photo from url
        path_segments = imageuri.getPathSegments();
        int total_segments = path_segments.size();
        file_name = path_segments.get(total_segments - 1);

        path.mkdirs();

        // if(i==0)
        //	first_image = path.toString() + "/" + file_name;

        InputStream input;
        OutputStream output;
        try {
          input = new BufferedInputStream(imageurl.openStream());
          fully_qualified_file_name = new File(path, file_name);
          output = new BufferedOutputStream(new FileOutputStream(fully_qualified_file_name));
          byte data[] = new byte[1024];
          int count;
          while ((count = input.read(data)) != -1) {
            output.write(data, 0, count);
          }
          output.flush();
          output.close();
          input.close();
          connection.disconnect();

          new folder_scanner(getApplicationContext(), fully_qualified_file_name);

          publishProgress(completed_downloads, total_files_to_download);
          if (this.isCancelled()) {
            writeProgress(completed_downloads, total_files_to_download);
            break;
          }

        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

        // creates required folders and subfolders if they do not exist already
        // boolean success = path.mkdirs();

        // makes request to download photos
        // DownloadManager.Request request = new DownloadManager.Request(imageuri);

        // set path for downloads
        // request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES,sub_path);

        // request.setDescription("Downloaded using Facebook Album Downloader");

        // DownloadManager dm = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);

        // download is enqueue in download list. it returns unique id for each download
        // download_id = dm.enqueue(request);

      }
      // returns the unique id. we are not using this id
      return true;
    }