我使用Android应用程序使用de post方法发送数据,并且php代码将此数据保存在MySql数据库中。当我使用wamp服务器时,它工作得很好。现在我想使用Godaddy托管,post方法没有获得Android应用程序发送的值。
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://url/insertar.php");
List<NameValuePair> postValues = new ArrayList<NameValuePair>(2);
postValues.add(new BasicNameValuePair("imei",imei));
postValues.add(new BasicNameValuePair("fecha",fecha));
postValues.add(new BasicNameValuePair("hora",hora));
postValues.add(new BasicNameValuePair("latitud",Slatitud));
postValues.add(new BasicNameValuePair("longitud",Slongitud));
postValues.add(new BasicNameValuePair("precision",Sprecision));
postValues.add(new BasicNameValuePair("operador",operador));
postValues.add(new BasicNameValuePair("tipored",tiporedmovil));
postValues.add(new BasicNameValuePair("nivelsenal", nivelseñaldbm)); //(servidor,cliente)
postValues.add(new BasicNameValuePair("lac",lac));
postValues.add(new BasicNameValuePair("cid",cid));
postValues.add(new BasicNameValuePair("mnc",mnc));
postValues.add(new BasicNameValuePair("mcc",mcc));
httppost.setEntity(new UrlEncodedFormEntity(postValues));
HttpResponse respuesta = httpclient.execute(httppost); //se envian los datos y se espera una respuesta del servidor
HttpEntity ent = respuesta.getEntity();/*y obtenemos una respuesta*/
tetServidor = EntityUtils.toString(ent);
} catch (Exception e) {
tetServidor="SERVIDOR NO DISPONIBLE";
e.printStackTrace();
}
接下来是php代码:
<?php
include("conectarconBD.php");
$imei=$_POST["imei"];
$fecha=$_POST["fecha"];
$hora=$_POST["hora"];
$latitud=$_POST["latitud"];
$longitud=$_POST["longitud"];
$presicion=$_POST["precision"];
$operador=$_POST["operador"];
$tipored=$_POST["tipored"];
$nivelsenal=$_POST["nivelsenal"];
$lac=$_POST["lac"];
$cid=$_POST["cid"];
$mnc=$_POST["mnc"];
$mcc=$_POST["mcc"];
$con=mysql_connect($host,$usuario,$pw)or die("Problemas al conectar");
mysql_select_db($bd,$con) or die("Problemas al conectar la base de datos");
mysql_query("INSERT INTO nivelsenal (imei,fecha,hora,latitud,longitud,presicion,operador,tipored,nivelsenal,lac,cid,mnc,mcc)VALUES ('$imei','$fecha','$hora','$latitud','$longitud','$presicion','$operador','$tipored','$nivelsenal','$lac','$cid','$mnc','$mcc')",$con);
?>
POST方法每次都获得一个空白值。有人可以帮助我。非常感谢!