• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 987
  • Last Modified:

HttpClient with Cookies

Hi,
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("https://signin.ebay.co.uk/ws/eBayISAPI.dllco_partnerid=2&siteid=3&UsingSSL=0");
    loginMethod.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
    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", "");

    try
    {
      client.executeMethod(loginMethod);
      System.out.println("authenticaed...");
      System.out.println("*********************");
      System.out.println(loginMethod.getResponseBodyAsString());
    }
    catch (Exception ex)
    {
      ex.printStackTrace();
    }

Any help would be much appreciated

Cheers
Angus
0
amacfarl
Asked:
amacfarl
  • 6
  • 6
1 Solution
 
objectsCommented:
try using CookiePolicy.BROWSER_COMPATIBILITY
and setting User-Agent to mimic a browser
0
 
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="https://signin.ebay.co.uk/ws/eBayISAPI.dll?co_partnerid=2&siteid=3&UsingSSL=0">

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

Any hints?
0
 
objectsCommented:
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
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
amacfarlAuthor Commented:
I assume by JS you mean:

https://secureinclude.ebaystatic.com/js/e453/uk/signin/signin_base_e4531uk.js

How can this be downloaded?

Cheers
Angus
0
 
objectsCommented:
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
0
 
amacfarlAuthor Commented:
There is this one

https://secureinclude.ebaystatic.com/js/e453/uk/signin/signin_body_e4531uk.js

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

//44@@m9
ebay.oDocument.oPage.onBeforeLoad=function()

{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();}

ebay.oDocument.oPage.signIntoToolbar=function()

{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;}}}

ebay.oDocument.oPage.setOptimCookie=function()

{this.parent.oCookieJar.setOptimizationCookie();}

window.init=null;window.setOptimCookie=function(){ebay.oDocument.oPage.setOptimCookie()};

// b=2748702 -->
0
 
amacfarlAuthor Commented:
FYI the code that I included above is only the part where I found the references.
0
 
objectsCommented:
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.

this.setOptimizationCookie=function()
{with(this.oGlobals.oClient)
{if(((bIE||bNav)&&iVer>=4)||bFirefox||bSafari)
this.writeCookielet("ebay","js","1");}}
this.getDate=function(pYears,pMonths,pDays)
{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;}
this.getBitFlag=function(pHex,pPos)
{var b=pHex.hex2Dec().toString(2);return pHex?b.charAt(b.length-pPos-1):"";}
this.setBitFlag=function(pHex,pPos,pVal)
{var b="",p,i;if(pHex)
{b=pHex.hex2Dec().toString(2);}
else
{for(i=0;i<=pPos;i++)
{b+="0";}}
p=b.length-pPos-1;return parseInt(b.substring(0,p)+pVal+b.substring(p+1),2).dec2Hex();}}
0
 
amacfarlAuthor Commented:
any ideas?
0
 
CEHJCommented:
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
0
 
objectsCommented:
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.

0
 
amacfarlAuthor Commented:
http://www.java-tips.org/other-api-tips/httpclient/how-to-use-http-cookies.html

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!!!
Thanks
0
 
objectsCommented:
no worries :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now