|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Dec 2003
Messaggi: 1776
|
[Android] Inviare una richiesta http
Nella mia app (la prima che realizzo) devo inviare una richiesta http ad uno script php che ho sul mio sito.
Assieme alla richiesta devo mandare dei parametri tramite post. Lo sto facendo così Codice:
public void postData(String from, String to, String date, String time, String searchby, String type, String orderby) {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.miosito.it/android/provahttp.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("from", from));
nameValuePairs.add(new BasicNameValuePair("to", to));
nameValuePairs.add(new BasicNameValuePair("date", date));
nameValuePairs.add(new BasicNameValuePair("time", time));
nameValuePairs.add(new BasicNameValuePair("searchby", searchby));
nameValuePairs.add(new BasicNameValuePair("type", type));
nameValuePairs.add(new BasicNameValuePair("orderby", orderby));
// Url Encoding the POST parameters
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e) {
// writing error to Log
e.printStackTrace();
}
// Making HTTP Request
try {
HttpResponse response = httpclient.execute(httppost);
// writing response to log
Log.d("Http Response:", response.toString());
} catch (ClientProtocolException e) {
// writing exception to log
e.printStackTrace();
} catch (IOException e) {
// writing exception to log
e.printStackTrace();
}
}
Cosa sto sbagliando? |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 22:45.



















