我有一个 android 应用程序,我使用它使用 http post 将数据发布到网站,但它没有将任何数据发布到网站。
在我的安卓代码中:
postParameters.add(new BasicNameValuePair("latitude", Double.toString(latitude)));
postParameters.add(new BasicNameValuePair("longitude", Double.toString(longitude)));
response = CustomHttpClient.executeHttpPost("url", postParameters);
在 executeHttpPost 方法中
public static String executeHttpPost(String url, ArrayList postParameters)
throws Exception {
BufferedReader in = null;
try {
HttpClient client = getHttpClient();
HttpPost request = new HttpPost(url);
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(
postParameters);
request.setEntity(formEntity);
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity()
.getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
String result = sb.toString();
return result;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
这是php源码
$lat=$_POST['latitude'];
$long=$_POST['longitude'];
mysql_connect('localhost','welcome','Welcome123') or die('conn error');
mysql_select_db('es') or die('select error');
$query = "insert into GEO_LOC (GEO_LOC_LAT,GEO_LOC_LONG) values ($lat,$long)";
$result = mysql_query($query);
if($result)
{
echo 1;
}
else echo "Database Error";
?>
但是这个 post 方法并没有做任何事情。我错过了什么吗?我需要添加任何额外的东西吗?