Howzit,

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.

So,
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?

Thanx

public static void Main()
        {
            var AccountUserName = "UserName";
            var AccountPassword = "Password";
            var Url = new Uri("https://www.myURL.com");

            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();
            Console.WriteLine(data.ToString());
            reader.Close();
        }

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

Edited 5 Years Ago by phoenix911: n/a

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()
        {
            InitializeComponent();
          webBrowser1.DocumentText = HttpPost("https://www.myURL.com/login.php", "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);
            os.Close();

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

            StreamReader sr = new StreamReader(resp.GetResponseStream());
            return sr.ReadToEnd().Trim();
        }

Edited 5 Years Ago by phoenix911: n/a

This article has been dead for over six months. Start a new discussion instead.