1
I am developing a Xamarin Forms application that basically uses the Getasync function through Httpclient(Uri requestUri):
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 http://xxx.xx.xxx.xx:81/AppWebServiceBase/AppService.svc/json/WebServiceUrl ) only this redirection is not done by the app but by the hosting service itself, let’s say if you hit the link http://www.appwebservice.meusite.com.br in the browser it will be automatically redirected to the url http://xxx.xx.xxx.xx:81/AppWebServiceBase/AppService.svc/json/WebServiceUrl.
On the UWP platform this works correctly, but on Android and iOS platforms 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)
Error iOS:
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 www address...
Note: I changed the urls and I did the error handling, I put in summary form where the error is located, I hope I was clear in doubt.
Strange that the bars in the stacktrace are inverted (""). Internet addresses have normal bars ("/"). There may be an error in redirecting on your host?
– Diego Rafael Souza
@Diegorafaelsouza so it’s really weird, but I took a look and it’s right on the host
– V. Godoy