Jaunt-api cookie issue



我试图登录雅虎邮件jaunt-api,但得到"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);
        }

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

最新更新