I've to programmatically 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:8080/PCC/servlet/tpservlet";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
CookieContainer CookieC = new CookieContainer();
string data =
String.Format("USERID={0}&transactiontype={2}&FIID={3}&AUTHENTICATIONURL={4}&TARGET={5}",
"DDBDB3099C5C04D36B91C0EA786C0996", "729E13B7AFB57796A30",
"UserInqAuthActionBean", "1111",
"
http://atl50test2/CLKPCB/111111118/Site/TransfersPayments/opserror.asp",
"BillPay.viewPayees");
byte[] buffer = Encoding.UTF8.GetBytes(data);
req.AllowAutoRedirect = false;
req.KeepAlive = true;
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = 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.CookieContainer = CookieC;
Stream reqst = req.GetRequestStream(); // add form data to request
stream
reqst.Write(buffer, 0, buffer.Length);
reqst.Flush();
reqst.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
string landingpage= res.Headers["Location"];
CookieC.Add(res.Cookies);
foreach (Cookie cook in CookieC.GetCookies(req.RequestUri))
{
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.Current.Response.AppendCookie(cookie);
}
//This statement fails
HttpContext.Current.Response.Redirect(landingpage);
I have to do the similar thing like automatically login to a third pary web
Steven Cheng said:
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.