473,839 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Login to website using HttpWebRequest + AllowAutoRedire ct + POST + Going MAD!

I'm trying to login to the www.vodafone.ie website using
It works fine with IE/Firefox and the .NET Web Control too, just not
with my code.
I think it's a redirect 302 problem.
I'm using this code in a ASP.NET 2.0 application just in case that
maybe someone knows a better way to do this?

If request.AllowAu toRedirect = true I get back a page saying
"Services We're sorry, there was a problem processing your request.
Please try again, if the problem persists please contact Customer Care"
This code works on other sites, just not this one.

I tried setting request.AllowAu toRedirect = false and then get the
value of the Location header and then perform a GET, but the Location
header contains "http://www.vodafone.ie/myv/services/error/error.jsp"
so it has already failed!

I have the method I use to POST below follow by a dump of the HTTP
Any ideas/hints/tips would be appreciated. Thanks.

Here's the code I use to call the HttpPostRedirec t() method below:

NetworkCredenti al credentials = new NetworkCredenti al(username,
CookieContainer cookies = new CookieContainer ();

string data = "username=" + username + "&password= " + password;
string webpage = HttpPostRedirec t(
"https://www.vodafone.ie/myv/services/login/Login.shtml", data,
credentials, cookies);
protected string HttpPostRedirec t(string uri, string data,
NetworkCredenti al networkCredenti als, CookieContainer cookies)
System.Net.Http WebRequest req =
(HttpWebRequest )System.Net.Web Request.Create( uri);
req.Method = "POST";
req.ContentType = "applicatio n/x-www-form-urlencoded";
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.1; SV1; .NET CLR 2.0.50727)";
req.KeepAlive = true;
req.CookieConta iner = cookies;
req.Credentials = networkCredenti als;
req.AllowAutoRe direct = false;

byte[] bytes = System.Text.Enc oding.ASCII.Get Bytes(data);
req.ContentLeng th = bytes.Length;
System.IO.Strea m os = req.GetRequestS tream();
os.Write(bytes, 0, bytes.Length);

System.Net.Http WebResponse resp =
(HttpWebRespons e)req.GetRespon se();
if (resp == null) return null;

cookies.Add(req .RequestUri, resp.Cookies);

// 302 REDIRECT?
string webpage;
if (resp.StatusCod e == HttpStatusCode. Found)
string newLocation = resp.Headers["Location"];
webpage = HttpGet(newLoca tion, networkCredenti als,
System.IO.Strea mReader sr = new
System.IO.Strea mReader(resp.Ge tResponseStream ());
webpage = sr.ReadToEnd(). Trim();
return webpage;
Here are the HTTP request/response headers when I use Firefox to do it:

POST /myv/services/login/Login.shtml HTTP/1.1
Host: www.vodafone.ie
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
Gecko/20061204 Firefox/
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,ima ge/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.vodafone.ie/
Content-Type: application/x-www-form-urlencoded
Content-Length: 42
username=XXXXXX XXXX&password=X XXX&x=16&y=6

HTTP/1.x 302 Moved Temporarily
Server: Sun-ONE-Web-Server/6.1
Date: Thu, 18 Jan 2007 00:54:55 GMT
Content-Length: 0
Content-Type: text/html
Cache-Control: private,no-cache,max-age=0
Location: https://www.vodafone.ie/myv/index.jsp
Set-Cookie: JSESSIONID=10AE DBFCA615C2372A7 6E4B2CDC02D5D;P ath=/
Set-Cookie: SITESELECTION=P ERSONAL;Expires =Thu, 25-Jan-2007 00:54:55

GET /myv/index.jsp HTTP/1.1
Host: www.vodafone.ie
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
Gecko/20061204 Firefox/
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,ima ge/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.vodafone.ie/
Cookie: JSESSIONID=10AE DBFCA615C2372A7 6E4B2CDC02D5D;

HTTP/1.x 200 OK
Server: Sun-ONE-Web-Server/6.1
Date: Thu, 18 Jan 2007 00:54:56 GMT
Content-Type: text/html;charset=IS O-8859-1
Cache-Control: private,no-cache,max-age=0
Transfer-Encoding: chunked

Jan 18 '07 #1
0 12807

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Gill Bates | last post by:
I'm trying to login to a banking site (https://www.providentconnection.com) using vb.net. I've tried many variations of WebClient and HttpWebRequest; none of which I've got to work. My latest version is: Dim myWebClient As New WebClient Dim nvc As New NameValueCollection nvc.Add("Login", username) nvc.Add("Password", password)
by: n8 | last post by:
Hi, Hi have to do the followign and have been racking my brain with various solutions that have had no so great results. I want to use the System.Net.WebClient to submit data to a form (log a user in) and then redirect to the correct article. Here is the scenerio. If you are not logged into the site for certain articles you are
by: PokerJoker | last post by:
My company has a third party purchased website that we use to allow clients to log in and view/modify orders in our system. It has its own login page, but I would like to add a form to my companies own website to post the login directly (for client conveniance reasons). Below is the code that I'm attempting to use, the post seems to be working fine, but I'm getting an error back that "WebTrac Pro is not available at this time, Please...
by: Brett | last post by:
I'm trying three different methods for logging into a webmail account. In Post1() and Post2(), I always get back the login page. Not the page after logging in. On TryCookies(), I'm not sure. It will run but there are some other things that need to take place. Any suggestion on what is wrong with the Post1() and Post2() or how to get TryCookies() going? Any other guidance is appreciated. Private Sub TryCookies() Dim uri As New...
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in the past in other places, and while the help was much appreciated, it seemed everyone just wanted to 'theoretically' explain how to do it, but when I tried to do it myself, I couldn't login. I want to simply pass the email address and password to...
by: Victor | last post by:
hi guys. In my project, now I am using a asp.net login control and a customized membership provider to do the form authentication. Now I want some function that user can skip the login form and be authenticated and login the system automatically base on the username and password already in the session. Is that possible to do ? and how to do it? Cheers Victor
by: Rama Jayapal | last post by:
i use the following code to login to a website but i dont achieve my purpose can anybody help me on this //code to request the page webRequest = HttpWebRequest.Create(url) as HttpWebRequest;
by: twebb72 | last post by:
Scratching my head for a while on this one... This project uses code from "Understanding HttpWebRequest CookieContainer?" post on this site. C#, asp.net 2.0 The following code supplies credentials to the login page properly, if I change the POST credentials, it responds with the invalid login page. On the second get request (after a successful login), it continually redirects to the main page as if the session was over. Here is the code......
by: mcfly1204 | last post by:
I am attempting to use WebRequest to access a page that requires a login/password to access. My last WebRequest continues to timeout. Any help or thoughts would be appreciated. namespace FormsAuthTest { class Program { static void Main(string args) { HttpWebRequest request = null;
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.