我正在尝试将数据发送到我的php文件并获得响应,但无法做到这一点我不知道为什么但我没有在我的php服务器上收到任何价值。请帮帮我
Android代码:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2/first.php");
try {
List<NameValuePair> nvp= new ArrayList<NameValuePair>(2);
nvp.add(new BasicNameValuePair("uid", "mirza"));
nvp.add(new BasicNameValuePair("pass", "mirza"));
httppost.setEntity(new UrlEncodedFormEntity(nvp));
HttpResponse response = httpclient.execute(httppost);
}
catch(IOException e){
}
}
PHP代码:
$ user = $_POST ["uid"];
$ pwd = $_POST ["pass"];
$con= mysql_connect("localhost","root");
if(! $con)
{
die("Not able to connect");
}
mysql_select_db("try", $con);
$result=mysql_query("Select * from info where uid=' $user 'and pass=' $pwd '");
if( mysql_num_rows( $result)<=0)
{
echo "unsuccessful";
}
else{
echo "successful";
}
mysql_close( $con);
?>
答案 0 :(得分:1)
您似乎正在使用私人IP地址http://10.0.2.2/first.php
。
你在同一个界面吗?如果没有,请检查一下,我建议你下载一个可以ping到特定IP地址的应用程序,如果你无法ping这个ip:10.0.2.2然后很明显你不能得到任何回复..
答案 1 :(得分:0)