您好我正在使用以下代码将数据发布到服务器,但它将空值发布到服务器。谁能告诉我这段代码有什么问题?
HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = 新的 HttpPost(url);
Log.i("name",name);
Log.i("email",email);
Log.i("subject",subject);
Log.i("mobile",mobile);
Log.i("url",url);
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5);
nameValuePairs.add(new BasicNameValuePair("name", name));
nameValuePairs.add(new BasicNameValuePair("email", email));
nameValuePairs.add(new BasicNameValuePair("mobile", mobile));
nameValuePairs.add(new BasicNameValuePair("subject", subject));
nameValuePairs.add(new BasicNameValuePair("message", message));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity=response.getEntity();
// Toast.makeText(getApplicationContext(), response + "", Toast.LENGTH_LONG).show();
String responseText = EntityUtils.toString(entity);
Log.i("Response",responseText + "");
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}