I need some advice on how to go about doing this little side project.

Theres a website that uses xml feeds to populate the whole page (i dont care if thats good or bad), I can access these feeds when I'm logged in, but as soon as I'm logged out i cannot access these, which is fine.

This brings me to the point i am now. I would like to replicate the site in a windows app using C#. But I'm kinda lost to this when it comes to http request(posts, get or whatever). Im assuming c# can do this without a problem.

step one, would be to probably send a post method to the URL with my details?
step two, would be access the xml feeds and process? (which is easy enough as i used a local copy of the xml doc to do this)

any help on where i could start to do the login process?


public static void Main()
            var AccountUserName = "UserName";
            var AccountPassword = "Password";
            var Url = new Uri("");

            NetworkCredential myCred = new NetworkCredential(AccountUserName, AccountPassword);
            CredentialCache myCache = new CredentialCache();
            myCache.Add(Url, "3", myCred);

            //Needed for ignoring the invalid SSL certificate on my test enviroment
            //ServicePointManager.ServerCertificateValidationCallback = Validator;
            //this doesnt seem to work anyhow

            WebRequest req = WebRequest.Create(Url);
            req.PreAuthenticate = true;
            req.Credentials = myCache;
            WebResponse resp = req.GetResponse();

            StreamReader reader = new StreamReader(resp.GetResponseStream());
            var data = reader.ReadToEnd().Trim();

public static bool Validator(object sender, X509Certificate certificate, X509Chain chain)
            return true;

this is what i got so far, but still doesnt seem to work

Sorry I have put this project aside after the last post, I am however back onto this though.

the response i get after posting this is the page that wants the login details.. What am i doing wrong here?

changed my code to the following

public Form1()
          webBrowser1.DocumentText = HttpPost("", "username=[username]&password=[password]");

        private string HttpPost(string URI, string Parameters)
            WebRequest req = WebRequest.Create(URI);
            //req.Proxy = new System.Net.WebProxy("ProxyURL", false); but i dont use this

            req.ContentType = "application/x-www-form-urlencoded";
            req.Method = "POST";

            byte[] bytes = Encoding.ASCII.GetBytes(Parameters);
            req.ContentLength = bytes.Length;

            Stream os = req.GetRequestStream();
            os.Write(bytes, 0, bytes.Length);

            WebResponse resp = req.GetResponse();
            if (resp == null) return null;

            StreamReader sr = new StreamReader(resp.GetResponseStream());
            return sr.ReadToEnd().Trim();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.