我正在将数据从 Android 设备保存到 MySQL。我的代码使用 localhost 可以正常工作,但是当我使用托管域尝试它时。它给了我和错误。
返回错误
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
AsyncTask 中的 Java 代码
.
.
.
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);
.
.
.
请帮我解决这个问题。它再次使用本地主机工作。
编辑:
PHP 代码:这只是为了测试我的设备是否可以访问给定的 URL
<?php
echo "Ive been reached.";
//Codes to connect DB and To Insert goes here
?>