如果用户已经登录到站点,如何在不需要任何身份验证的情况下从站点下载文件?我们是否应该传递 cookie。怎么做?我正在使用Firefox浏览器。确切的场景是这样的。有一个需要身份验证的站点。我希望在用户通过浏览器登录站点后,我希望我的代码应该从 flashgot 插件提供的 cookie 字符串中获取该 cookie,并使用该 cookie 向门户发送一个获取请求,这样就不需要身份验证。我试过这个:我通过一个字符串传递cookie,
cookie=rPopHome=1; FF_JoinPromo=true; __utma=140252452.845088738.1348089486.1348089486.1348089486.1; __utmb=140252452.6.10.1348089486; __utmc=140252452; __utmz=140252452.1348089486.1.1.utmcsr=adf.ly|utmccn=(referral)|utmcmd=referral|utmcct=/7hYuB; ff_membership=SlyL0JODTZMIdfYHy/7imBJHqyHhO9ZHNE4bwnFPzoGYgPVEEneUMsfqaFDsqR+w9EotIx9i7PPL7ZIp1CiUSOtx0Y4mE1GmxayYmnJVD/z5aCTS2qT7fTItiqOprW8rlsEYw2Br7OoETaF3L1RGRQai1zlFQw6QO9qBEPKXC7rOx5LuEEKYlrZFKvuD/m7uDc6SWDJyaW67sRfo/bpb/Q==; ff_referrer_hash=o7e2qf0;
request.setUrl(url);
request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
cookieJar->setCookiesFromUrl(QNetworkCookie::parseCookies(cookie),url.host());
manager.setCookieJar(cookieJar);
reply=manager.get(request);
但我收到以下错误,下载的文件包含此消息:
<h1>HTTP/1.0 401 Unauthorized</h1>
<p>You have attempted to download via a Premium download link, but we could not verify your Premium account details.</p>
<p></h1>
我也更改了用户代理,它仍然失败:
request.setRawHeader("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1");