将数据插入本地主机xampp

时间:2015-01-05 13:35:42

标签: php android eclipse

当我将数据保存到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 ");         
    }

log cat:

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()

我没有使用异步任务,我正在扩展活动

甚至在MR.HU'NG

之后尝试了192.168.0.123:80

再次出错

Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject

1 个答案:

答案 0 :(得分:0)

ANDROID DEVICE上的192.168.0.1/exmpl/insertData.php的返回值与您的PC不同,因为,DEVICE中的192.168.0.1指向自身,而不是指向您的apache服务器。

您必须使用本地路由器分配的计算机IP,或者将仿真器配置为使用固定IP。

可能192.168.0.1/exmpl/insertData.php返回的内容类似于“找不到页面”。