Я пытаюсь подключиться к веб-сайту и отправить много разных почтовых запросов через разные страницы по всему сайту.Я достиг первого шага: подключить сайт.Но теперь мне нужно изменить URL запроса и сохранить тот же httpURLConnection.
На данный момент мой код:
//openning the connection to the website
URL url = new URL("http://path/to/the/website");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
//preparing the post arguments
Map<String, Object> params = new HashMap<>();
params.put("Action", "connect_user");
params.put("login", "login");
params.put("password", "password");
StringBuilder sb = new StringBuilder();
for (Entry<String, Object> e : params.entrySet()) {
if (sb.length() != 0)
sb.append('&');
sb.append(URLEncoder.encode(e.getKey(), "UTF-8"));
sb.append('=');
sb.append(URLEncoder.encode(String.valueOf(e.getValue()), "UTF-8"));
}
//writing the request and sending
BufferedOutputStream writer = new BufferedOutputStream(conn.getOutputStream());
writer.write(sb.toString().getBytes(Charset.forName("UTF-8")));
writer.flush();
На этом этапе я подключен и успешно вошел в систему. ЧтоМне нужно сделать сейчас, чтобы перенаправить то же соединение на второй URL-адрес.Спасибо.