Problem with HttpClient in iOS app RRS feed

  • Question

  • User222362 posted

    I have the following code in my app. private HttpClient CreateRestClient() { var client = new HttpClient() { BaseAddress = new Uri("http://tvcnaba.org/api/") }; client.MaxResponseContentBufferSize = 256000; try { MediaTypeWithQualityHeaderValue mtqhv; MediaTypeWithQualityHeaderValue.TryParse("application/json", out mtqhv); client.DefaultRequestHeaders.Accept.Add(mtqhv); } catch (Exception e) { int x = 1; } return client; }

    This works as expected in my Android and WinPhone apps but in the iOS app when you get to client.DefaultRequestHeaders.Accept.Add(mtqhv); mtqhv is null.

    Yes, I'm aware of the issues with App Transport Security. As far as I can tell I have my info.plist file setup correctly to allow http to work with my domain. I've also tested using https://google.com/ as the BaseAddress with the same results.

    So, what am I missing?

    Can someone point me to a publicly available web service that uses https that I can test with?

    Thanks, Dave

    Wednesday, February 15, 2017 9:46 PM


  • User222362 posted

    I still don't know what was causing this but after creating a new solution from scratch so I could remove Windows Phone Silverlight 8.1 from the targets of the PCL to allow me to work with Universal Windows and then adding my code back in the iOS app is working again. I didn't do anything in this relative to App Transport Security.

    Obviously something not right in the project that wasn't working but I have no idea how to figure out what it was.


    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Saturday, February 18, 2017 1:55 PM