0

** で囲まれた場所は、symbol メソッド getValue() が見つからないというエラーをスローします。

ちなみに、このコードはマインクラフトのアカウント名の有効性をチェックするプログラムの一部です。それらが利用可能かどうか。

 public String connectToMigrate() {
  try {
  Connection.Response response = 
    Jsoup.connect("https://account.mojang.com/migrate").execute();
  Document doc = response.parse();
  Element authToken = doc.select("input[name^=authenticityToken]").get(0);
  Map cookies = response.cookies();
  Connection connection = 
    Jsoup.connect("https://account.mojang.com/migrate/check")
    .data("authenticityToken", authToken.val())
    .data("mcusername", this.username)
    .data("password", this.password)
    .method(Connection.Method.POST)
    .followRedirects(true);
  connection.timeout(10000);
  for (Object cookie : cookies.entrySet()) {
      connection.cookie((String) **cookie.getValue**(), (String)  **cookie.getKey**());
  }
  Connection.Response postResponse = connection.execute();
  if (postResponse.body().toLowerCase().contains("invalid username"))
    return "error";
  if (postResponse.body().toLowerCase().contains("already been migrated"))
    return "error";
  if (postResponse.body().toLowerCase().contains("locked out"))
    return "error";
  if (postResponse.body().toLowerCase().contains("bought minecraft"))
    return "error";
  if (postResponse.body().toLowerCase().contains("too many failed attempts")) {
    getNewProxy();
    return "try again";
  }
  if (postResponse.body().toLowerCase().contains("error")) {
    return "try again";
  }

  Map cookies2 = postResponse.cookies();
  Connection connection2 = 
    Jsoup.connect("https://account.mojang.com/migrate/chooseEmail");
  for (Object cookie : cookies2.entrySet()) {
      connection2.cookie((String) **cookie.getValue()**, (String) **cookie.getKey()**);
  }
  connection2.timeout(10000);
  Connection.Response postResponse2 = connection2.execute();
  String s = postResponse2.body().toLowerCase();
  s = s.split("i want to use <strong>")[1];
  s = s.split("</strong>")[0];
  String email = s;
  return email; } catch (Exception e) {
}return "try again";
}
4

3 に答える 3

2

cookiegetValue()メソッドを含まないオブジェクトです。を呼び出す前に、適切なタイプにキャストする必要がありますgetValue()

于 2012-07-16T18:53:24.707 に答える
1

Javaでマップを使用する方法を誤解していると思います。それは非常に簡単なはずです。これを試してください:

Map<String,String> cookies = response.cookies();
[...]
for ( Map.Entry<String,String> e : cookies.entrySet()){
    connection.cookie( e.getKey(), e.getValue() );
}

ただし、次のようにすると、すべての Cookie を一度にコピーできます。

connection.cookies( response.cookies() ); 
于 2012-07-16T19:08:35.217 に答える
0

getCookiesJSoupConnection.Responseオブジェクトでは を返しますMap<String, String>

したがって、最初のforループで:

for (Object cookie : cookies.entrySet())

eachcookieは でありSetSetこれらのメソッドをサポートしていません (ドキュメントを参照してください)。

代わりに、これらのループではMap、Cookie 名になるキーを反復処理する必要があります。

for (Object cookie : cookies.keySet())

これでそれぞれcookie キーになり、元のマップの値を でクエリできますcookies.get(cookie)

しかし、JsoupConnectionでは既に Cookie を直接コピーすることができます ( docsを参照)。ループは必要ありません。

connection.cookies(response.cookies());
于 2012-07-16T19:02:37.030 に答える