Forum Xamarin.Android

HttpWebRequest fails with timeout in debug mode from VS 2012

Pretty new to Xamarin and Android development...

So I have a block of code that appears as:

`
var httpReq = HttpWebRequest.Create(string.Format(@"http://somewebapiaddress"));
httpReq.ContentType = "application/json";
httpReq.Method = "GET";

        try
        {
            using (HttpWebResponse response = httpReq.GetResponse() as HttpWebResponse)
            {
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    // error
                }

                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    var content = reader.ReadToEnd();
                    if (string.IsNullOrWhiteSpace(content))
                    {
                        // empty content
                    }
                    else
                    {
                        // response is ...
                    }

                }
            }
        }
        catch (Exception ex)
        {
            string txt = ex.Message;
        }

`

That eventually fails with a timeout. The exact same code in a DOS Console app works fine.
Not sure how to get past this. The code is currently sitting in the OnCreate handler of a secondary activity

Posts

  • CheesebaronCheesebaron DKInsider, University mod

    Have you set the Internet permission for your app in the AndroidManifest.xml? Does the device or Emulator have Internet connectivity?

  • MichaelFenskeMichaelFenske USMember ✭✭

    So the manifest looks like this:
    <?xml version="1.0" encoding="utf-8"?>





    And not sure how to check the emulator for connectivity.

    The details look like this

  • MichaelFenskeMichaelFenske USMember ✭✭

    Oh nevermind. I've been fighting my company's proxy settings forever, this is another example of them making my life difficult I believe. Using my WiFi hotspot and I can make things go.

Sign In or Register to comment.