Android: How to send variable parameters with GetHttp?


I'm new in Android and I am blocked with a problem I don't know how to solve: from my app I'm trying to send a message of this form to a server in order to modify a xml file on the server:


I managed to make it work with fixed values of param1, param2 and param3, i.e. using the code below I modify the values of the xml file on the server to 1, 2 and 3:

private OnClickListener InitialPosListener = new OnClickListener() { @Override public void onClick(View v) { String x00 = InitialPosX.getText().toString(); String y00 = InitialPosY.getText().toString(); String z00 = InitialPosZ.getText().toString(); float x0 = Float.valueOf(x00); float y0 = Float.valueOf(y00); float z0 = Float.valueOf(z00); new RequestTask().execute(https://myserver/index.php?x0=1&y0=2&z0=3); } }; class RequestTask extends AsyncTask<String, String, String>{ @Override protected String doInBackground(String... uri) { HttpClient httpclient = new DefaultHttpClient(); HttpResponse response; String responseString = null; try { response = httpclient.execute(new HttpGet(uri[0])); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpStatus.SC_OK){ ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().writeTo(out); out.close(); responseString = out.toString(); } else{ //Closes the connection. response.getEntity().getContent().close(); throw new IOException(statusLine.getReasonPhrase()); } } catch (ClientProtocolException e) { //TODO Handle problems.. } catch (IOException e) { //TODO Handle problems.. } return responseString; } @Override protected void onPostExecute(String result) { super.onPostExecute(result); //Do anything with response.. } }

But my problem is that I want to send not fixed values, but the values (variables) which are input by the user and are read in the "InitialPosListener" : x00, y00 and z00...

Is there a way to do this? Thanks a lot


It looks like you are just executing HTTP GET to your server. Calling

new RequestTask().execute("https://myserver/index.php?x0=" + x00 + "&y0=" + y00 + "&z0=" + z00);

will do what you want.


In doInBackground(String... uri) method, try something like this:

DefaultHttpClient client1 = new DefaultHttpClient(); HttpResponse response = null; HttpGet httpGet = null; try { httpGet = new HttpGet(URL); response = client1.execute(httpGet); ...... }


  • Is there a built in python function to escape a string of unicode characters into unicode escape seq
  • Rendering  In Front of Special Characters
  • Qpython unicode strings
  • Safari WebCrypto API RSA-OAEP encryption
  • Send data from edittext to listview
  • Reading space separated values file in c++ error
  • Jquery Mobile pageLoading() Method how does it work?
  • Simulate click Geckofx vb,net
  • $wpdb not working in file of WordPress plugin
  • NHibernate Validation Localization with S#arp Architecture
  • how to do an event when i swipe from fragment to the other
  • Update CALayer sublayers immediately
  • JFileChooser in front of fullscreen Swing application
  • RectangularRangeIndicator format like triangular using dojo
  • Validaiting emails with Net.Mail MailAddress
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • sending/ receiving email in Java
  • Convert array of 8 bytes to signed long in C++
  • AT Commands to Send SMS not working in Windows 8.1
  • Cannot Parse HTML Data Using Android / JSOUP
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • Acquiring multiple attributes from .xml file in c#
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • JTable with a ScrollPane misbehaving
  • Understanding cpu registers
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Getting Messege Twice Using IMvxMessenger
  • apache spark aggregate function using min value
  • How can I remove ASP.NET Designer.cs files?
  • unknown Exception android
  • EntityFramework adding new object to nested object collection
  • Checking variable from a different class in C#
  • Recursive/Hierarchical Query Using Postgres
  • Running Map reduces the dimensions of the matrices
  • Sorting a 2D array using the second column C++
  • failed to connect to specific WiFi in android programmatically
  • java string with new operator and a literal
  • How can I use threading to 'tick' a timer to be accessed by other threads?
  • How to load view controller without button in storyboard?