我正在将数据从Android设备保存到MySQL。我的代码使用Localhost工作正常,但是当我尝试使用我的托管域时。它给我和错误。PHP返回无效请求错误
返回错误
ERROR
The requested URL could not be retrieved
While trying to process the request:
POST /insert.php HTTP/1.1
Transfer-Encoding: chunked
Content-Type: application/x-www-form-urlencoded
Host: mydomain.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4)
The following error was encountered:
Invalid Request
Java代码里面的AsyncTask
.
.
.
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("user_id", userId));
HttpPost httppost = new HttpPost("http://mydomain.com/insert.php");
HttpClient httpclient = new DefaultHttpClient();
UrlEncodedFormEntity urlEncodeFormEntity = new UrlEncodedFormEntity(nameValuePairs);
urlEncodeFormEntity.setChunked(true);
httppost.setEntity(urlEncodeFormEntity);
HttpResponse response = httpclient.execute(httppost);
.
.
.
请帮我解决了这个问题。它再次使用Localhost工作。
编辑:
PHP代码:这仅仅是一个测试,如果我的设备能达到给定的URL
<?php
echo "Ive been reached.";
//Codes to connect DB and To Insert goes here
?>
解决了这个问题,你可以在这里提供insert.php代码和logcat的也? –
@MishuCn我认为php代码没有必要发布,但正如你所要求的。我张贴我的PHP代码。任何帮助,不胜感激。请帮助我们。 – jayellos
没有错误也没有在Logcat中发现异常,“请求的URL无法检索...”是HttpResonse的值。 – jayellos