我正在开发一个Android应用程序。我需要连接到我的PHP,我使用HttpPost。这是我的代码。我已经遵循了几个教程,但它不起作用。错误是PHP没有接收我从应用程序代码传递的参数。虽然它正确地连接到PHP。我用邮差在PHP中找到错误,但它工作得很好。我把我的代码放在这里:
private void httppostconnect(ArrayList<NameValuePair> parametros, String urlwebserver) {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(urlwebserver);
httppost.setEntity(new UrlEncodedFormEntity(parametros));
//ejecuto peticion enviando datos por POST
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch(Exception e) {
Log.e("GetBuscadas", "Error in http connection "+e.toString());
}
}
你能说清楚这些参数是什么吗,你的" parameters "变量。通常的问题是不发送内容类型头。