problem with cookies for bestbuy website!! help
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   chiranjeevi_jaladi
Posted On:   Tuesday, March 9, 2004 10:07 PM

hi, i have a program which takes a url, gets html code, goes through it and then finds more links and then goes into them recursively. i am using the HttpClient from jakarta website. it works great for most websites, but i am having problems with bestbuy.com as it is saying that my browser is not set to recieve cookies.. actually i used to use the HttpClient from Java and it worked for all the websites and because of this problem i changed to this HttpClient and still its the same problem.. can you please tell me what i am doing wrong?? i am posting part of the code that i keep calling from a main program.. Helper.getDomDoc public class Helper { public static Cookie[] cookies; pub   More>>

hi,
i have a program which takes a url, gets html code, goes through it and then finds more links and then goes into them recursively. i am using the HttpClient from jakarta website. it works great for most websites, but i am having problems with bestbuy.com as it is saying that my browser is not set to recieve cookies.. actually i used to use the HttpClient from Java and it worked for all the websites and because of this problem i changed to this HttpClient and still its the same problem.. can you please tell me what i am doing wrong??
i am posting part of the code that i keep calling from a main program.. Helper.getDomDoc






			

public class Helper
{
public static Cookie[] cookies;
public static int count;

public static Document getDOMDoc(String urlString, boolean getSourceString1)
{
InputStream st = null;
try
{


String strURL = urlString;


HttpState initialState = new HttpState();

Cookie mycookie = new Cookie(".foobar.com", "mycookie", "stuff", "/", null, false);

initialState.addCookie(mycookie);


HttpClient httpclient = new HttpClient();

if(count == 1)
{
HttpState latterState = new HttpState();
latterState.addCookies(cookies);
latterState.setCookiePolicy(CookiePolicy.COMPATIBILITY);
httpclient.setState(latterState);
}
else
{
initialState.setCookiePolicy(CookiePolicy.COMPATIBILITY);
httpclient.setState(initialState);
}


GetMethod httpget = new GetMethod(strURL);

int result = httpclient.executeMethod(httpget);

if(count != 1)
{
// Get the cookies
cookies = httpclient.getState().getCookies();
}

// Display the cookies
//System.out.println("***************************************************");
//System.out.println("Present cookies: ");
//for (int i = 0; i < cookies.length; i++) {
// System.out.println(" - " + cookies[i].toExternalForm());
//}
//System.out.println("***************************************************");
// Release current connection to the connection pool once you are done

count = 1;
st = httpget.getResponseBodyAsStream();

BufferedInputStream bin = new BufferedInputStream(st);

if (getSourceString1)
{
bin.mark(1000000);
DataRover.sourceString = getSourceString(bin);
bin.reset();
}

Document doc = (bin == null) ? null : tidy.parseDOM(bin, null);

httpget.releaseConnection();

return doc;
}
catch (Exception ex)
{
System.out.println(ex);
ex.printStackTrace();
}
return null;
}
   <<Less
About | Sitemap | Contact