我正在將數據從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