gpt4 book ai didi

php - android Php Mysql 连接

转载 作者:行者123 更新时间:2023-11-29 12:53:09 24 4
gpt4 key购买 nike

请帮忙

我正在尝试使用 php 和 android 制作登录表单。但是在 php MySql 和 android 之间建立连接时出现问题。

当我使用 127.0.0.1 时,可以通过浏览器访问 php 文件,但在 Android 单元上它显示

连接被拒绝当我使用 10.0.2.2 时,无法通过浏览器访问 php 文件,并且在 Android 单元上显示

连接超时

这是我的代码

            httpclient=new DefaultHttpClient();
httppost= new HttpPost("http://10.0.2.2/my_folder_inside_htdocs/check.php"); // make sure the url is correct.
//add your data
nameValuePairs = new ArrayList<NameValuePair>(2);
// Always use the same variable name for posting i.e the android side variable name and php side variable name should be similar,
nameValuePairs.add(new BasicNameValuePair("name",et.getText().toString().trim())); // $Edittext_value = $_POST['Edittext_value'];
nameValuePairs.add(new BasicNameValuePair("password",pass.getText().toString().trim()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//Execute HTTP Post Request
response=httpclient.execute(httppost);
// edited by James from coderzheaven.. from here....
ResponseHandler<String> responseHandler = new BasicResponseHandler();
final String response = httpclient.execute(httppost, responseHandler);
System.out.println("Response : " + response);

runOnUiThread(new Runnable() {
public void run() {
tv.setText("Response from PHP : " + response);
dialog.dismiss();
}
});

最佳答案

在 HttpPost 中使用您的 IP 地址

   httppost= new HttpPost("http://ipaddress/my_folder_inside_htdocs/check.php"); 

我认为这会有所帮助you

关于php - android Php Mysql 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24446604/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com