1
Answer

How to login using C#

Ask a question
Jacob

Jacob

14y
2.8k
1
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)