I love MonoTouch, but sometimes MonoTouch lets me down very very bad. The latest scenario was simple in theory. The scenario is

  • Create an HttpWebRequest
  • Provide the NTLM credentials of the user to the HttpWebRequest

The helper method below simply creates and returns an HttpWebRequest

 private HttpWebRequest CreateRequest_NTLM(string url, string username, string password, string domain)
    HttpWebRequest result = (HttpWebRequest)WebRequest.Create(url);
    NetworkCredential networkCredential = new NetworkCredential(username, password, domain);
    CredentialCache credentialCache = new CredentialCache();
    credentialCache.Add(new Uri(url), "NTLM", networkCredential);
    result.Credentials = credentialCache;

    System.Net.IWebProxy proxy = System.Net.WebRequest.DefaultWebProxy;

    if (proxy != null)
     result.Proxy = proxy;
    result.Timeout = 30000;
    result.Method = "GET";
    return result;

Here we create the HttpWebRequest and call BeginGetResponse

 private AuthenticateUser(string username, string password, string domain)
	HttpWebRequest request = CreateRequest_NTLM("http://www.protectedweb.com/",username,password,domain);
	request.BeginGetResponse(new AsyncCallback(AuthenticateUserCompleted),request);
 private void AuthenticateUserCompleted(IAsyncResult asyncResult)
	//Upon successfull authentication some business code executes here 

Below is the WireShark capture output when the code is run on .NET Framework on a windows machine

Below is the WireShark capture output when the code is run iOS simulator on Mac OSX

As you can see HttpWebRequest of MonoTouch just hangs after the first 303 response of the server and our AuthenticateUserCompleted method is never called.

Posted in: MonoTouch  Tags:
Comments are closed