httunit session handling
Santosh Gdr <[email protected]> Tue, 4 Nov 2014 18:47:52 +0530
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Message-ID | <CAP9o19hYmhHEZZZe2XNqXUT+o_qoGpgrkZZzi6FGTiR2Sq-vuQ@mail.gmail.com> |
--===============5797022072445722751==
Content-Type: multipart/alternative; boundary=001a11c1a46860907e0507084aea
--001a11c1a46860907e0507084aea
Content-Type: text/plain; charset=UTF-8
Hi...
I am using HttpClient to handle session.Here is my code to handle session
using httpclient. But httpclient won't handle ajax calls.I am planning to
move to httpunit to overcome my problem.Basically I have a referral URL(or
authentication server) from which I need to get cookies and session and
store it in client.And use this client across website to get logged user
information.
What is the appropriate solution for this using httpunit.
credentialsURL="https://www.,,,,.com./sapLogin.aspxHOOK_URL=
https://authentication.server.address
&username=<username>&password=<password>";
try{
HttpEntity entity=null;
HttpGet httpget=null;
HttpResponse response=null;
httpclient = new DefaultHttpClient();
httpget = new HttpGet(credentialsURL);
httpget.setHeader(HttpHeaders.USER_AGENT, "Mozilla/5.0 (Windows NT
6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.120
Safari/535.2");
response = httpclient.execute(httpget);
entity = response.getEntity();
if (entity != null) {
EntityUtils.consume(entity);
}
}
catch(Exception e){
}
return httpclient;
--001a11c1a46860907e0507084aea
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hi...<div><br></div><div><div>I am using HttpClient to han=
dle session.Here is my code to handle session using httpclient. But httpcli=
ent won't handle ajax calls.I am planning to move to httpunit to overco=
me my problem.Basically I have a referral URL(or authentication server) fro=
m which I need to get cookies and session and store it in client.And use th=
is client across website to get logged user information.</div><div>What is =
the appropriate solution for this using httpunit.</div><div>credentialsURL=
=3D"<a href=3D"https://www">https://www</a>.,,,,.com./sapLogin.aspxHOO=
K_URL=3D<a href=3D"https://authentication.server.address">https://authentic=
ation.server.address</a>&username=3D<username>&password=3D<=
;password>";</div></div><div><br></div><div><div>try{</div><div><sp=
an class=3D"" style=3D"white-space:pre"> </span>HttpEntity entity=3Dnull;=
</div><div><span class=3D"" style=3D"white-space:pre"> </span>HttpGet htt=
pget=3Dnull;</div><div><span class=3D"" style=3D"white-space:pre"> </span=
>HttpResponse =C2=A0response=3Dnull;</div><div><span class=3D"" style=3D"wh=
ite-space:pre"> </span></div><div><span class=3D"" style=3D"white-space:=
pre"> </span>httpclient =3D new DefaultHttpClient();</div><div><span clas=
s=3D"" style=3D"white-space:pre"> </span></div><div><span class=3D"" sty=
le=3D"white-space:pre"> </span> =C2=A0 =C2=A0 =C2=A0 =C2=A0httpget =3D new=
HttpGet(credentialsURL);</div><div><span class=3D"" style=3D"white-space:p=
re"> </span> =C2=A0 =C2=A0=C2=A0</div><div><span class=3D"" style=3D"white=
-space:pre"> </span> =C2=A0 =C2=A0 =C2=A0 =C2=A0httpget.setHeader(HttpHead=
ers.USER_AGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2=
(KHTML, like Gecko) Chrome/15.0.874.120 Safari/535.2");</div><div><sp=
an class=3D"" style=3D"white-space:pre"> </span> =C2=A0 =C2=A0 =C2=A0 =C2=
=A0response =3D httpclient.execute(httpget);</div><div><span class=3D"" sty=
le=3D"white-space:pre"> </span> =C2=A0 =C2=A0 =C2=A0=C2=A0</div><div><span=
class=3D"" style=3D"white-space:pre"> </span> =C2=A0 =C2=A0 =C2=A0 =C2=A0=
entity =3D response.getEntity();</div><div><span class=3D"" style=3D"white-=
space:pre"> </span> =C2=A0 =C2=A0 =C2=A0 =C2=A0</div><div><span class=3D""=
style=3D"white-space:pre"> </span> =C2=A0 =C2=A0 =C2=A0 =C2=A0if (entity=
!=3D null) {</div><div><span class=3D"" style=3D"white-space:pre"> </spa=
n> =C2=A0 =C2=A0 =C2=A0 =C2=A0<span class=3D"" style=3D"white-space:pre"> <=
/span></div><div><span class=3D"" style=3D"white-space:pre"> </span> =C2=
=A0 =C2=A0 =C2=A0 =C2=A0<span class=3D"" style=3D"white-space:pre"> </span>=
EntityUtils.consume(entity);</div><div><span class=3D"" style=3D"white-spac=
e:pre"> </span> =C2=A0 =C2=A0 =C2=A0 =C2=A0}</div><div><span class=3D"" s=
tyle=3D"white-space:pre"> </span>}</div><div><span class=3D"" style=3D"wh=
ite-space:pre"> </span>catch(Exception e){</div><div><span class=3D"" sty=
le=3D"white-space:pre"> </span></div><div><span class=3D"" style=3D"whit=
e-space:pre"> </span>}</div><div><span class=3D"" style=3D"white-space:pr=
e"> </span>return httpclient;</div><div><span class=3D"" style=3D"white-s=
pace:pre"> </span></div></div></div>
--001a11c1a46860907e0507084aea--
--===============5797022072445722751==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
--===============5797022072445722751==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Httpunit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/httpunit-develop
--===============5797022072445722751==--