向本地主机插入数据 xampp
insert data to local host xampp
当我将数据保存到 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
return [=168.0.1/exmpl/insertData.php 在 ANDROID DEVICE 上的值与您的 PC 不同,因为,192.168.0.1 在DEVICE 指向它自己,而不是你的 apache 服务器。
您必须使用您机器的 IP,由本地路由器分配,或者将您的模拟器配置为使用某个固定 IP。
192.168.0.1/exmpl/insertData.php 可能 return 类似于 "page not found".
当我将数据保存到 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
return [=168.0.1/exmpl/insertData.php 在 ANDROID DEVICE 上的值与您的 PC 不同,因为,192.168.0.1 在DEVICE 指向它自己,而不是你的 apache 服务器。
您必须使用您机器的 IP,由本地路由器分配,或者将您的模拟器配置为使用某个固定 IP。
192.168.0.1/exmpl/insertData.php 可能 return 类似于 "page not found".