Is there any way to use firefox's cookies with the Apache HttpClient class?
I obviously don't know a ton abo开发者_开发技巧ut cookies, if they'd even be compatible, etc, etc. If this is possible, can someone show an example of how?
I'm not quite sure what you mean by "use Firefox cookies". Here's a snipet of code that I wrote to grab data from the Goolge Reader API, by passing a cookie along with the Apache HttpClient request.
It needs to send a cookie that Google gives you upon connection ("SID") along with its request. Is this what you are looking for?
// Obtain SID
GetMethod getLogin = new GetMethod("https://www.google.com/accounts/ClientLogin?service=reader&Email="+
login+"&Passwd="+password);
client.executeMethod(getLogin);
String loginText = getLogin.getResponseBodyAsString();
// The value of SID is loginText.substring (4,firstLineLength)
BufferedReader reader = new BufferedReader(new StringReader(loginText));
String SID = loginText.substring(4, reader.readLine().length() );
GetMethod grabData = new GetMethod("http://www.google.com/reader/atom/user/-/state/com.google/broadcast");
grabData.setRequestHeader("Cookie", "SID="+SID);
client.executeMethod(grabData);
精彩评论