Android and iOS platforms error in HttpClient.GetAsync (Uri requestUri) function for redirect URL

1

I'm developing a Xamarin Forms application that basically uses the GetAsync (Uri requestUri) function through the HttpClient:

HttpClient httpClient = new HttpClient(new NativeMessageHandler());
var uri = new Uri(http://www.appwebservice.meusite.com.br);
httpResponseMessage = await httpClient.GetAsync(uri);

This url automatically redirects to another url with ip (something like this link ) but this redirect is not done by the app but by the hosting service itself, let's say if you hit the link link in the browser it will automatically be redirected to the url link .

On the UWP platform this works properly, however on Android and iOS platforms it gives error.

Android error:

    --- End of managed Java.Net.MalformedURLException stack trace ---
java.net.MalformedURLException: java.lang.NumberFormatException: Invalid int: "81\AppWebServiceBase\AppService.svc\json\WebServiceUrl"
    at java.net.URL.<init>(URL.java:192)
    at java.net.URL.<init>(URL.java:139)
    at com.squareup.okhttp.internal.http.HttpEngine.followUpRequest(HttpEngine.java:1009)
    at com.squareup.okhttp.Call.getResponse(Call.java:285)
    at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:228)
    at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:199)
    at com.squareup.okhttp.Call.access$100(Call.java:34)
    at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:162)
    at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
    at java.lang.Thread.run(Thread.java:856)

iOS Error:

Invalid URI: Invalid port specified.
  at System.Uri.CreateThis (System.String uri, System.Boolean dontEscape, System.UriKind uriKind) [0x0007b] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.6.1.4/src/mono/mcs/class/referencesource/System/net/System/UriExt.cs:55 
  at System.Uri..ctor (System.String uriString) [0x00014] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.6.1.4/src/mono/mcs/class/referencesource/System/net/System/URI.cs:408 
  at ModernHttpClient.NativeMessageHandler+DataTaskDelegate.DidReceiveResponse (Foundation.NSUrlSession session, Foundation.NSUrlSessionDataTask dataTask, Foundation.NSUrlResponse response, System.Action'1[T] completionHandler) [0x00106] in /Users/paul/code/paulcbetts/modernhttpclient/src/ModernHttpClient/iOS/NSUrlSessionHandler.cs:184 
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.6.1.4/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.6.1.4/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.6.1.4/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.6.1.4/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 
  at System.Runtime.CompilerServices.TaskAwaiter'1[TResult].GetResult () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.6.1.4/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357 
  at OuvidoriaApp.Services.SaudeWebService+<ServiceCall>d__0.MoveNext () [0x000f1] in C:\Plastic.Workspace\OuvidoriaApp\OuvidoriaApp\OuvidoriaApp\Services\OuvidoriaWebService.cs:44 

If I put the url already redirected, ie put the address with IP the application works normally, the problem seems to be at the address www ...

Note: I changed the urls and made the error handling, I put in a summarized way where the error is located, I hope it was clear in the doubt.

    
asked by anonymous 05.03.2018 / 14:06

0 answers