2
votes

I'm trying to access a specific URL that returns a json (https://api.cartolafc.globo.com/mercado/destaques).

In my Xamarin C# class I coded this way:

public async void DownloadDataAsync()
    {
        string baseUrl = "https://api.cartolafc.globo.com";
        string address = "/mercado/destaques";

        try
        {
            var httpClient = new HttpClient();



            httpClient.BaseAddress = new Uri(baseUrl);

            var resp = await httpClient.GetAsync(address);

            if (resp.IsSuccessStatusCode)
            {
                var respStr = await resp.Content.ReadAsStringAsync();

                var listaAtletas = JsonConvert.DeserializeObject<List<Atleta>>(respStr);

            }
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex.Message);

        }

    }

I'm always receiving the following exception:

System.Net.WebException: Error getting response stream (ReadDone2): ReceiveFailure ---> System.Exception: at System.Net.WebConnection.HandleError (System.Net.WebExceptionStatus st, System.Exception e, System.String where) [0x0003a] in <8dac28ffb2cb41cba0b572038da86c99>:0 at System.Net.WebConnection.ReadDone (System.IAsyncResult result) [0x0006e] in <8dac28ffb2cb41cba0b572038da86c99>:0 at System.Runtime.Remoting.Messaging.AsyncResult.Invoke (System.Runtime.Remoting.Messaging.AsyncResult ) [0x00000] in <8c304e4006094a46a7950338a3b3cb5d>:0 at System.Runtime.Remoting.Messaging.AsyncResult.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00000] in <8c304e4006094a46a7950338a3b3cb5d>:0 at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00096] in <8c304e4006094a46a7950338a3b3cb5d>:0 at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <8c304e4006094a46a7950338a3b3cb5d>:0 at System.Net.WebConnection.HandleError (System.Net.WebExceptionStatus st, System.Exception e, System.String where) [0x0003a] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/System/System.Net/WebConnection.cs:447 --- End of inner exception stack trace --- at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x0005e] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1029 at System.Threading.Tasks.TaskFactory1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func2[T,TResult] endFunction, System.Action1[T] endAction, System.Threading.Tasks.Task1[TResult] promise, System.Boolean requiresSynchronization) [0x00014] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/FutureFactory.cs:550 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 at System.Net.Http.HttpClientHandler+c__async0.MoveNext () [0x003ce] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.cs:379 --- End of inner exception stack trace --- at System.Net.Http.HttpClientHandler+c__async0.MoveNext () [0x0047a] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.cs:383 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 …

When I use others URL like: https://coffeemaker.herokuapp.com/foursquare.json?q[near]=Lima,%20PE&q[query]=Ceviche the request is successfully done.

What could be the reason for this specific URL doesn't work properly?

2
opened it in postman, ran fine. created WPF project just to see, got this nastiness. Something weird with the URL, either the SSL level or an invalid cert. No time now, will dig in more, but thought you'd be interested in the "hint". Exception thrown: 'System.Net.Http.HttpRequestException' in mscorlib.dll System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.Joe Healy

2 Answers

0
votes

Your stack trace is very vague, perhaps this blog here is similar to your issue. just make sure in debugging mode that your web service url is proper at GetAsync() call. also you might wanna try ModernHttpClient or Refit instead of using plain HttpClient.

0
votes

I was with the same problem on my release version (debug was working fine). Checking "Internet" permission on my droid project did the trick.

how to fix you error