【问题标题】:send cookies with urlconnection使用 urlconnection 发送 cookie
【发布时间】:2015-12-24 16:54:29
【问题描述】:

我正在尝试使用 cookie 登录 Steam。尝试了两种方法,第一种是:

URL url = new URL("https://steamcommunity.com/");

CookieManager cookieManager = new CookieManager();
CookieHandler.setDefault(cookieManager);
CookieStore cookieStore = cookieManager.getCookieStore();

HttpCookie steamAuthCookie = new HttpCookie("steamMachineAuth*****************", "SteamMachineAuthValue");
steamAuthCookie.setDomain(".steamcommunity.com");
steamAuthCookie.setPath("/");

HttpCookie steamLogin = new HttpCookie("steamLogin", "SteamLoginCookieValue");
steamLogin.setDomain(".steamcommunity.com");
steamLogin.setPath("/");

cookieStore.add(new URI("https://steamcommunity.com/"), steamAuthCookie);
        cookieStore.add(new URI("https://steamcommunity.com/"), steamLogin);

URLConnection urlConnection = url.openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
urlConnection.connect();
urlConnection.getContent();

不起作用,Steam 仍然让我登录 我以为 URLConnection 不支持 CookieManager,所以我找到并尝试了第二种方式:

URL url = new URL("https://steamcommunity.com/");
URLConnection urlConnection = url.openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.8");

String cookie = "steamMachineAuth*****************=****************************************;steamLogin=**************************************************************";
urlConnection.setRequestProperty("Cookie",cookie);

urlConnection.connect();
urlConnection.getContent();

Steam 仍然让我登录。 坚持下去,甚至不知道如何检查 - 是否发送了 cookie。 发送 cookie 的正确方法是什么?

【问题讨论】:

  • 您可能需要设置的不仅仅是一个 cookie。我的浏览器显示了 steamcommunity.com 的 12 个 cookie,包括 steamLoginsteamLoginSecure
  • 我知道要正确登录,我必须有 2 个 cookie - steamLogin 和 SteamMachineAuth。在 Chrome 中对其进行了测试-删除了除这两个之外的所有内容-steam 认出了我,删除了 steamLogin 或 SteamMachineAuth-steam 要求我登录。

标签: java cookies steam


【解决方案1】:

安装像 Wireshark 这样的网络嗅探器,手动登录以在浏览器中进行蒸汽分析并分析发送的数据。将它与您的 java 程序发送的数据逐个字节地进行比较。

【讨论】:

  • 谢谢,如果找不到其他解决方案会这样做。
猜你喜欢
  • 2016-06-20
  • 1970-01-01
  • 2010-11-30
  • 2015-06-22
  • 2015-06-25
  • 1970-01-01
  • 2012-11-05
  • 2011-11-03
  • 1970-01-01
相关资源
最近更新 更多