У меня возникают некоторые проблемы при вызове Webservice с использованием HttpURLConnection .
После поиска мне нужно позвонить в Webservice и отправить запрос через ipv6 или ipv4 на сервер, я получил ipv4 или ipv6, но я не знаю, как отправить запрос с использованием ipv6 или ipv4, вот мой код:
java.net.URL url;
String response = "";
try {
url = new URL(URL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(50000);
conn.setConnectTimeout(50000);
conn.setReadTimeout(50000);
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(getPostDataString(postDataParams));
writer.flush();
writer.close();
os.close();
int responseCode = conn.getResponseCode();
Log.d("Util", "Response Code" + URL + " - " + responseCode);
if (responseCode == HttpsURLConnection.HTTP_OK) {
Log.d("Util", "If" + responseCode);
String line;
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = br.readLine()) != null) {
response += line;
}
} else if (responseCode == HttpURLConnection.HTTP_CLIENT_TIMEOUT) {
Log.d("Util", "TimeOut" + responseCode);
response = "";
}
Log.d("jai", "response :" + response);
if (response == null || response == "" || response.equals("")) {
Log.d("jai", "response : null" + response);
}
} catch (Exception e) {
e.printStackTrace();
}
return response;