当我
将数据保存到 Web 服务器时,我的应用程序运行良好,但是当我将其保存在本地主机数据库上时,它会给出 Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
错误..
这是我的代码:
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("www.website.com/exmpl/insertData.php"); //working perfectly
HttpPost httppost = new HttpPost("http://192.168.0.1/exmpl/insertData.php");
httppost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
Log.e("pass 1", "connection success ");
}
日志猫:
01-05 19:02:53.150: E/pass 1(28604): connection success
01-05 19:02:53.410: E/Fail 3(28604): org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
编辑如果我将 IP 地址更改为 192.168.0.123 则出错
01-06 10:00:37.560: E/Fail 1(4261): org.apache.http.conn.HttpHostConnectException: Connection to http://192.168.0.123 refused
01-06 10:00:37.570: E/AndroidRuntime(4261): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
而且我没有使用异步任务,我正在扩展活动
甚至尝试了 192.168.0.123:80 跟随 MR。胡恩
再次出错
Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
ANDROID 设备上的返回值 192.168.0.1/exmpl/insertData.php 与您的 PC 不同,因为 DEVICE 中的 192.168.0.1 指向自身,而不是您的 apache 服务器。
必须使用本地路由器分配的计算机 IP,或将模拟器配置为使用某些固定 IP。
可能,192.168.0.1/exmpl/insertData.php返回类似"找不到页面"的内容。