posting to an asp with cookies
I am trying to post to an asp and get a returning page. The page starts a session and sends me a cookie. How do I send it back in the request?
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();
}
}
I think i figured out you can't read and write in the same connection, but won't 开发者_JS百科you loose the cookie the server just sent? Any clarification would be helpful.
Regards.
yd.setRequestProperty("Cookie", "name=John;surname=Lennon;jsessionid=1234567890");
精彩评论