I've to programmaticall y login to a third party web app (Tomcat/apache) and
take the user to a landing page. I am able to programatically login
succesfullly but I am not able to redirect the browser to the landing page.
If I look at the logs on Tomcat side, I see the cookies are getting lost
somewhere even though I pass the cookies between successive requests. I would
appreciate any comments or suggestion rgeading how to take the user
successfully to the landing page.
string url = "http://10.112.60.86:80 80/PCC/servlet/tpservlet";
HttpWebRequest req = (HttpWebRequest )WebRequest.Cre ate(url);
CookieContainer CookieC = new CookieContainer ();
string data =
String.Format(" USERID={0}&tran sactiontype={2} &FIID={3}&AUTHE NTICATIONURL={4 }&TARGET={5}" ,
"DDBDB3099C5C04 D36B91C0EA786C0 996", "729E13B7AFB577 96A30",
"UserInqAuthAct ionBean", "1111",
"http://atl50test2/CLKPCB/111111118/Site/TransfersPaymen ts/opserror.asp",
"BillPay.viewPa yees");
byte[] buffer = Encoding.UTF8.G etBytes(data);
req.AllowAutoRe direct = false;
req.KeepAlive = true;
req.Method = "POST";
req.ContentType = "applicatio n/x-www-form-urlencoded";
req.ContentLeng th = buffer.Length;
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;
..NET CLR 1.1.4322; .NET CLR 2.0.50727)";
req.CookieConta iner = CookieC;
Stream reqst = req.GetRequestS tream(); // add form data to request
stream
reqst.Write(buf fer, 0, buffer.Length);
reqst.Flush();
reqst.Close();
HttpWebResponse res = (HttpWebRespons e)req.GetRespon se();
string landingpage= res.Headers["Location"];
CookieC.Add(res .Cookies);
foreach (Cookie cook in CookieC.GetCook ies(req.Request Uri))
{
HttpCookie cookie = new HttpCookie(cook .Name);
cookie.Name = cook.Name;
cookie.Value = cook.Value;
cookie.Domain = cook.Domain;
cookie.Expires = cook.Expires;
cookie.Path = cook.Path;
cookie.Secure = cook.Secure;
String str = String.Format(" Name {0}: Value {1}: Domain
{2}<BR>", cookie.Name, cookie.Value, cookie.Domain);
HttpContext.Cur rent.Response.A ppendCookie(coo kie);
}
//This statement fails
HttpContext.Cur rent.Response.R edirect(landing page);
I have to do the similar thing like automatically login to a third pary web
"Steven Cheng[MSFT]" wrote:
Hi Victor,
Have you got any further idea on this issue? If there is anything else we
can help, please feel free to post here.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.