Я пытаюсь опубликовать в asp и получить возвращающуюся страницу. Страница начинает сеанс и отправляет мне cookie. Как мне отправить его обратно в запросе?
URL oracle = new URL("http://taxinquiry.princegeorgescountymd.gov/taxsummary.aspx");
HttpURLConnection yc = (HttpURLConnection) oracle.openConnection();
yc.setDoOutput(true);
yc.setDoInput(true);
yc.setAllowUserInteraction(true);
yc.setRequestMethod("HEAD");
String cookie = yc.getHeaderField(5);
yc.disconnect();
HttpURLConnection yd = (HttpURLConnection) oracle.openConnection();
yd.setRequestMethod("POST");
yd.setRequestProperty("Content-Type", "text/html; charset=utf-8");
yd.setRequestProperty("Content-Length", "19004");
yd.setRequestProperty("Cache-Control", "private");
yd.setRequestProperty("Set-Cookie", cookie);
yd.setRequestProperty("X-AspNet-Version", "1.1.4322");
yd.setRequestProperty("X-Powered-By", "ASP.NET");
yd.setRequestProperty("Server", "Microsoft-IIS/6.0");
yd.setDoOutput(true);
HttpURLConnection.setFollowRedirects(true);
OutputStreamWriter out = new OutputStreamWriter(yd.getOutputStream());
out.write(data);
out.flush();
//out.write(data);
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(yd.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
Думаю, я понял, что вы не можете читать и писать в одном соединении, но не потеряете ли вы cookie, только что отправленный сервером? Любое разъяснение будет полезно.
С уважением.