運行在我的Android應用一個簡單的代碼對一些數據發送到服務器後,我收到此異常: java.lang.illegalstateexception:未知協議:HTTPjava.lang.illegalstateexception:未知協議:HTTP
這是代碼:
URL url = new URL("http://myserver");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write(myString.toString());
out.close();
我試過這個使用異步任務。 另外我得到這個錯誤與我使用的任何網址(例如http://www.google.com)。
Internet權限在清單文件中設置。
任何幫助?
權限嘗試用'URL url = new URL(「http:// myserver」)替換'URL url = new URL(http:// myserver);'' – Lal
這就是我在代碼中使用它。我只是把它放在這個問題中。 \t 有沒有其他建議? – Malm32
你能分享更多的描述性日誌嗎?這對你和社區都會有很大的幫助。 – cafebabe1991