HttpClient with Cookies

I am writing an application that manages ebay auctions.  Part of the requirements can only be met by login into ebay site.  I have written this code to manage the login but it is not working.  The result is: "Browser Not Accepting Cookies"

Can anyone help?

   HttpClient client = new HttpClient();
   client.getParams().setParameter("http.protocol.single-cookie-header ", "true");
    PostMethod loginMethod = new PostMethod("");
    loginMethod.addParameter("userid", "expertsexchangetest");
    loginMethod.addParameter("pass", "experts123");
    loginMethod.addParameter("MfcISAPICommand", "SignInWelcome");
    loginMethod.addParameter("siteid", "3");
    loginMethod.addParameter("UsingSSL", "1");
    loginMethod.addParameter("ru", "");    
    loginMethod.addParameter("pp", "");    
    loginMethod.addParameter("pa1", "");
    loginMethod.addParameter("pa2", "");
    loginMethod.addParameter("pa3", "");
    loginMethod.addParameter("i1", "");
    loginMethod.addParameter("pageType", "");
    loginMethod.addParameter("rtmData", "");

    catch (Exception ex)

Any help would be much appreciated

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
try using CookiePolicy.BROWSER_COMPATIBILITY
and setting User-Agent to mimic a browser
amacfarlAuthor Commented:
I have change the CookiePolicy and unfortunately it did not work.

How do I set the User-Agent to mimic a browser?

The other thing that is concerning me is the FORM that I am copying the variable from.  It has the following:

<form method="post" name="SignInForm" onsubmit="setOptimCookie();" action="">

I have not taken into consideration onsubmit="setOptimCookie();" , actually I cannot find any reference to it in the page.

Any hints?
Mick BarryJava DeveloperCommented:
it'll probably be in a js include, download the js and have a look what it does.
most likely its setting a cookie and is probably the cause of your problem
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

amacfarlAuthor Commented:
I assume by JS you mean:

How can this be downloaded?

Mick BarryJava DeveloperCommented:
same you you download any resource

the function does not appear to be in there, are there any othe js includes, or js on that page
amacfarlAuthor Commented:
There is this one

and I have found some references to setOptimCookie(), however I am not sure what it is doing, and whether it is the cause of the problem


{var cfg=ebay.oDocument.addConfig(new EBayToolbarConfig("ebaytoolbar"));cfg.signinButtonID="signInButton";cfg.signinFormID="SignInForm";cfg.pageTypes="708,123,706,109,698,121,958,955,867,161,2002,846,1769,1001,697,1828,567,917";this.setOptimCookie();this.initFocus();this.signIntoToolbar();}


{var cfg=this.parent.getConfig("ebaytoolbar");var toolbar=new EbayToolbar(this,"toolbar",cfg);var form=new EbayHTMLForm(this,cfg.signinFormID);form._registerEvent("onsubmit","signinToolbar");form.signinToolbar=function(){toolbar.onSignIn();}}

ebay.oDocument.oPage.initFocus=function(){var isUsernamePrepopulated=false;var cfg=this.parent.getConfig("signInConfig");if(cfg)

isUsernamePrepopulated=cfg.isUsernamePrepopulated;var de=document.forms["SignInForm"].elements;for(var i=0;i<de.length;i++){if(((de[i].type=="text")||(de[i].name=="pass"&&isUsernamePrepopulated))&&(de[i].value=="")){de[i].focus();break;}}}




// b=2748702 -->
amacfarlAuthor Commented:
FYI the code that I included above is only the part where I found the references.
Mick BarryJava DeveloperCommented:
looks like they have done there best to hide whats they are doing :)

the following function appears to being used and writing some cookies, there may well be others written.

{pYears=pYears?pYears:0;pMonths=pMonths?pMonths:0;pDays=pDays?pDays:0;var dt=new Date(),y=dt.getUTCFullYear(),m=dt.getMonth(),h=dt.getHours();y+=(y<1900)?1900:0;dt.setUTCFullYear(y+pYears);dt.setMonth(m+pMonths);dt.setHours(h+pDays*24);return dt;}
{var b=pHex.hex2Dec().toString(2);return pHex?b.charAt(b.length-pPos-1):"";}
{var b="",p,i;if(pHex)
p=b.length-pPos-1;return parseInt(b.substring(0,p)+pVal+b.substring(p+1),2).dec2Hex();}}
amacfarlAuthor Commented:
any ideas?
It would be a lot less time consuming for you simply to use a proxy with your browser and look at what's getting sent then mimic it. Eclipse Solex plugin is what i use
Mick BarryJava DeveloperCommented:
first load the form and then submit it in the same session that way the cookies should get looked after for you.
if they don't, then try another http client such as httpunit. You'll need to grab the rhino jar for javascript su[pport.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
amacfarlAuthor Commented:

In the link above is the answer!!  Two main problems with the code that I entered:

1) Load the form before hand
2) Set Cookie param at Client level, not Method Level
3) I am just dumb!!!

24 hours this one took for me to solve.  Tried everything.... even OpenSSL for the https connection which was not necessary.

However just a point of information.  OpenSSL has got to be the most unfriendly, screwed up piece of software there is around!!!!!  To install it you need a PHD in IT and be a complete geek.  I have a IT graduate degree and still it was impossible.  Sorry, just venting some anger!!!
Mick BarryJava DeveloperCommented:
no worries :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.