1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| public class connexion extends Activity{
private static final String LOG_TAG = "Log : ";
private final String mimeType = "text/html";
private final String encoding = "utf-8";
private String strURL;
private static final int REQUEST_SCAN = 0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//on récupère l'url présente dans l'EditText
Bundle bundle = getIntent().getExtras();
//Next extract the values using the key as
strURL = bundle.getString("NAME");
DefaultHttpClient hc=new DefaultHttpClient();
ResponseHandler <String> res=new BasicResponseHandler();
HttpPost postMethod=new HttpPost(strURL);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("Nom", "Bennour"));
nameValuePairs.add(new BasicNameValuePair("Prenom", "Mohamed"));
try {
postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
String response=hc.execute(postMethod,res);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} |
Partager