0

我正在尝试使用 jaunt-api 登录 yahoo 邮件,但出现“cookie 未启用问题”。我是 jaunt-api 的新手,所以请帮助我。我正在使用以下代码。

try
{
UserAgent userAgent = new UserAgent();
            userAgent.setCacheEnabled(false);
            userAgent.settings.autoSaveAsHTML = true;
            try{
                userAgent.cookieJar.saveCookies(new File("e:\\cookie.txt"));
            }catch(Exception e){}
            userAgent.visit("https://login.yahoo.com/m");                        

            try{
            userAgent.cookieJar.loadCookies(new File("e:\\cookie.txt"));
            }catch(Exception e){}

            Form form = userAgent.doc.getForm(0);
            form.setTextField("username", "*****@gmail.com");
            form.setPassword("passwd", "*******");
            form.submit();
            System.out.println(userAgent.doc.innerHTML());
            System.out.println(userAgent.getLocation());
        }catch(JauntException e){
            System.out.println(e);
        }
4

1 回答 1

0

Cookie 无法从文本文件加载到 Jaunt,您需要指定之前用于保存 cookie 的相同文件。(Jaunt 正在序列化 cookies 容器对象,所以除非这是 .txt 文件的内容,否则它不会工作)。

于 2016-02-10T21:39:52.877 回答