【发布时间】:2015-01-05 13:35:41
【问题描述】:
当我将数据保存到 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.HU'NG
又出错了
Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
【问题讨论】:
-
您是否在手机中测试此应用?如果是,请尝试在模拟器中运行。
-
用网络导航器测试你的网址
-
是的@ParmarS 我正在设备上而不是在模拟器上测试它......我无法设置模拟器......
-
因为我体验到设备检测不到本地主机,模拟器检测到。
-
所以,如果我们想将数据保存到本地主机,那么我们必须使用模拟器??