AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
params.put("username", username);
params.put("password", password);
client.post("192.168.12.4/administration/include/login.php", params, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String response) {
System.out.println("onSuccess");
Toast.makeText(getApplicationContext(), "MySQL DB has been informed about Sync activity", Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(int statusCode, Throwable error, String content) {
System.out.println("onFailure");
Toast.makeText(getApplicationContext(), "Error Occured", Toast.LENGTH_LONG).show();
}
});
如果我有上面的代码,可能会导致它转到public void onFailure(int statusCode, Throwable error, String content) {}
而不是public void onSuccess(String response) {}
其中192.168.12.4
是运行localhost的计算机的IP以及包含login.php
的项目所在的位置
答案 0 :(得分:1)
将“http or 'https
等协议添加到URL
。
更改URL
,
192.168.12.4/administration/include/login.php
到
http://192.168.12.4/administration/include/login.php
答案 1 :(得分:1)
如果这是开发人员计算机(运行模拟器的PC)进行模拟器测试,则必须将URL值更改为
http://10.0.2.2/administration/include/login.php
不要忘记在清单文件中添加它
<uses-permission android:name="android.permission.INTERNET" />