Java-在发布后读取cookie

Java-在发布后读取cookie,java,post,cookies,Java,Post,Cookies,在用java写帖子时,我很难阅读发送的cookies 这是我的密码: public static void main(String[] args) throws MalformedURLException, IOException { String urlParameters = "votebut="; String request = "http://www.runelocus.com/toplist/vote-17648.html"; URL url = new UR

在用java写帖子时,我很难阅读发送的cookies

这是我的密码:

public static void main(String[] args) throws MalformedURLException, IOException {
    String urlParameters = "votebut=";
    String request = "http://www.runelocus.com/toplist/vote-17648.html";
    URL url = new URL(request);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setInstanceFollowRedirects(false);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0");
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    connection.setRequestProperty("charset", "utf-8");
    connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
    connection.setUseCaches(false);

    DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
    wr.writeBytes(urlParameters);
    wr.flush();
    wr.close();
    List<String> cookies = connection.getHeaderFields().get("Set-Cookie");
    for (String cookie : cookies) {
        System.out.println("Cookies: " + cookie);
    }
    connection.disconnect();
}
publicstaticvoidmain(字符串[]args)引发畸形的异常,IOException{
字符串urlParameters=“votebut=”;
字符串请求=”http://www.runelocus.com/toplist/vote-17648.html";
URL=新URL(请求);
HttpURLConnection connection=(HttpURLConnection)url.openConnection();
connection.setDoOutput(真);
connection.setDoInput(true);
connection.setInstanceFollowDirections(false);
connection.setRequestMethod(“POST”);
setRequestProperty(“用户代理”、“Mozilla/5.0(Windows NT 6.1;WOW64;rv:16.0)Gecko/20100101 Firefox/16.0”);
connection.setRequestProperty(“内容类型”、“应用程序/x-www-form-urlencoded”);
setRequestProperty(“字符集”、“utf-8”);
connection.setRequestProperty(“Content Length”,“Integer.toString(urlParameters.getBytes().Length));
connection.setUseCaches(false);
DataOutputStream wr=新的DataOutputStream(connection.getOutputStream());
writeBytes(URL参数);
wr.flush();
wr.close();
List cookies=connection.getHeaderFields().get(“设置Cookie”);
用于(字符串cookie:cookies){
System.out.println(“Cookies:+cookie”);
}
连接断开();
}
这是它打印的内容:
Cookies:PHPSESSID=48863f8c3adcbddf0e77e7f1b450fc0e;路径=/

这就是我希望它打印的内容:
ki_=68debd85-c1af-f1ff-2e6c-4146755c6e26;ki_t=1354418220596%3B1354418220596%3B1354422379616%3B1%3B36

需要帮忙吗


谢谢

以这种方式读取cookies是不可能的

响应
http://www.rune...17648.html
您只能在响应头中获得
PHPSESSID
cookie

您正在查找的cookie(
ki_
ki_t
)由此文件中的JavaScript代码设置:

http://s3.amazonaws.com/ki.js/45645/919.js

因此,要真正获得cookie值,您需要复制浏览器行为或实际使用浏览器(请求html页面、解析它、下载参考资源(特别是
919.js
)并执行JavaScript代码)。

您在哪里设置预期的cookie?您能告诉我一种方法吗?我不太擅长html。也许是一个代码什么的?@user1869674我想不出你怎么能用Java来编程。我会使用浏览器和自动化集成工具(如Selenium)来完成这项任务。