Jacob

Jacob

  • NA
  • 1
  • 0

How to login using C#

Dec 30 2009 11:29 AM
Hello,
I am very new C#.
I am trying to log into http://mls.momls.com/SERetsMonmouth/Login.aspx with the following code and I am getting a 401 error. My user name and password are correct. I can manually log in through the browser.
But I am not sure about the code I wrote. It is based on what I read on the internet and after examining someone's code.
Please advice me on what I am doing wrong.

  1. this.digestAuth = this.GetAuth();
  2. HttpWebRequest request = (HttpWebRequest) WebRequest.Create(this.loginUrl);
  3. request.Accept = "*/*";
  4. request.UserAgent = this.userAgent;
  5. request.Headers.Add("RETS-Version", this.version);
  6. request.ProtocolVersion = HttpVersion.Version11;
  7. request.Headers.Add("Authorization", this.digestAuth);
  8. CredentialCache cache = new CredentialCache();
  9. cache.Add(new Uri(this.loginUrl), "Digest", new NetworkCredential(this.userName, this.password));
  10. request.Credentials = cache;
  11. HttpWebResponse response = (HttpWebResponse) request.GetResponse();


Answers (1)