Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

HttpWebRequest problem when distributed through Ad-Hoc

I have an application with a login. When testing the app, via Simulator or iPhone, everything is working as it should without any problems. It's connecting via WIFI to get the Login info and proceeding if the login is correct.
Now I wanted to distribute the app in the company via Ad-Hoc. After creating the IPA file and installing the app on the phone, I have the following problem: The Login is not working anymore, and it sems that it hangs when it gets to the HttpWebRequest and trying to make the async call.
The funny thing is, that if I test via Simulator or iPhone it works. Just not when installed through Ad-Hoc.
Does anyone know what the problem may be for that?
I also had a problem in the beginning with this, when it didn't connect at all, even not through the Simulator. The fix was to change the SSL/TLS implementation from "Mono (TLS v1.0)" to "Apple TLS (default)" in the advanced iOS build properties.

Here is the Code that makes the HttpWebRequest:

public static async Task<JsonValue> GetJSONDataAsync(string url, Xamarin.Forms.Page page = null)
            // Create an HTTP web request using the URL:
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
            request.ContentType = "application/json";
            request.Method = "GET";

           if(request != null) await page.DisplayAlert("Alert", "Created HttpWebRequest: " + request.ToString(), "OK");

    ///////                     it gets stuck here....                 /////////////////

            // Send the request to the server and wait for the response:
            using (WebResponse response = await request.GetResponseAsync().ConfigureAwait(false))
                await page.DisplayAlert("Alert", "Created WebResponse!", "OK");
                // Get a stream representation of the HTTP web response:
                using (Stream stream = response.GetResponseStream())
                    await page.DisplayAlert("Alert", "Streaming!", "OK");
                    // Use this stream to build a JSON document object:                        
                    JsonValue jsonDoc = await Task.Run(() => JsonObject.Load(stream));
                    return jsonDoc;
        catch (WebException ex)
            await page.DisplayAlert("WebException", "WebException!", "OK");
            throw ex;
        catch (Exception ex)
            await page.DisplayAlert("Exception", "Exception!", "OK");
            throw ex;

Any help is appreciated.

Sign In or Register to comment.