当我运行代码在mysql数据库服务器上上传数据时,我遇到了这个错误。 java.net.UnknownHostException:无法解析主机“192.168.0.110”:没有与主机名关联的地址。 我检查了我的IP地址192.168.0.110,但它的给予 错误。
这里是我的网址:
String url = "http:// 192.168.0.110/latTesting.php";
这里我的java代码在mysql数据库本地服务器上传lat lat
url = new URL(strings[0]);
String lat=strings[1];
String lang=strings[2];
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
String post_data = URLEncoder.encode("lat", "UTF-8") + "=" + URLEncoder.encode(lat, "UTF-8") + "&"
+ URLEncoder.encode("lang", "UTF-8") + "=" + URLEncoder.encode(lang, "UTF-8");
Log.d(TAG, "doInBackground: lat="+lat);
Log.d(TAG, "doInBackground: lang="+lang);
bufferedWriter.write(post_data);
bufferedWriter.flush();
bufferedWriter.close();
outputStream.close();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
String result = "";
String line = "";
while ((line = bufferedReader.readLine()) != null) {
result += line;
}
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return result;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}