Web サイトのフォームをオートコンプリートするアプリケーションを作成しています (Java で)。
これを行うにはユーザーがログインする必要があり、これが問題が発生する場所です。これは、ログイン要求に対する応答の一部です。
セット Cookie: PHPSESSID=3fvr31tb3c1iplpi3vqpvloar3; パス=/; ドメイン=.bursatransport.com
セット Cookie: PHPSESSID=eanaj1d9egd73uiome0jtsed43; パス=/; ドメイン=.bursatransport.com
私がテストした限り、最後のものは正しいものです(ブラウザでPHPSESSID Cookieを変更してテストしました)
私のアプリケーションは最初の Cookie を保持します。その結果、フォームを送信すると、ユーザーがログインしていないかのように動作します。最後の Cookie を保持している場合もありますが、フォームを正常に送信できませんでした (以前と同じ)。
これが私のログインコードです:
String query = String
.format("returnTo=/&Login[username]=%s&Login[password]=%s&Login[rememberMe]=0&yt4=",
URLEncoder.encode(name, charset),
URLEncoder.encode(password, charset));
CookieManager manager = new CookieManager();
manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(manager);
URLConnection mycon = new URL(url).openConnection();
mycon.setDoOutput(true);
mycon.setRequestProperty("Accept-Language", "ro-RO,ro;q=0.8,en-US;q=0.6,en;q=0.4");
mycon.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
mycon.setRequestProperty("Accept-Charset", charset);
mycon.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded;charset=" + charset);
OutputStream output = null;
output = mycon.getOutputStream();
output.write(query.getBytes(charset));
mycon.getContent();
ブラウザのリクエストに正しく応答するため、これはサーバーの問題ではありません(私はフィドラーでそれらを聞いています)