Advertisement
Guest User

Untitled

a guest
Apr 4th, 2012
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. package com.test.test;
  2.  
  3.  
  4.  
  5.  
  6. import java.io.ByteArrayOutputStream;
  7.  
  8. import org.apache.http.HttpEntity;
  9. import org.apache.http.HttpResponse;
  10. import org.apache.http.HttpStatus;
  11. import org.apache.http.StatusLine;
  12. import org.apache.http.client.HttpClient;
  13. import org.apache.http.client.methods.HttpGet;
  14. import org.apache.http.impl.client.DefaultHttpClient;
  15.  
  16. import android.app.Activity;
  17. import android.os.Bundle;
  18.  
  19.  
  20. public class TesthttpActivity extends Activity {
  21.     /** Called when the activity is first created. */
  22.     @Override
  23.     public void onCreate(Bundle savedInstanceState) {
  24.         super.onCreate(savedInstanceState);
  25.         setContentView(R.layout.main);
  26.        
  27.         HttpClient httpClient = new DefaultHttpClient();  
  28.         String url = "http://10.0.2.2/myfolder/save.php?valeur1=123&valeur2=456";
  29.         HttpGet httpGet = new HttpGet(url);
  30.         HttpResponse response = httpClient.execute(httpGet);
  31.         StatusLine statusLine = response.getStatusLine();
  32.         if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
  33.             HttpEntity entity = response.getEntity();
  34.             ByteArrayOutputStream out = new ByteArrayOutputStream();
  35.             entity.writeTo(out);
  36.             out.close();
  37.             String responseStr = out.toString();
  38.             // do something with response
  39.         } else {
  40.             // handle bad response
  41.         }
  42.  
  43.        
  44.  
  45.        
  46.        
  47.         }
  48.  
  49.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement