Reputation: 8425
We are trying to make a call to web service (nonsecure i.e. HTTP) in Xamarin.iOS
. As it is an http
URL we have added NSAppTransportSecurity
to bypass the secure access.
Currently, we are using HttpClient
with NSUrlSessionHandler
so that ATS config
specified in info.plist
gets applied.
client = new HttpClient(new NSUrlSessionHandler());
Problem #1
Now, the issue is whenever we are firing the web service request and after that, if we switch to a different app and come back to our app, the request gets stuck and does not return anything. if we stay on our app, it returns the response successfully.
Problem #2
In order to resolve Problem#1
issue of switching app, we tried client = new HttpClient(new CFNetworkHandler());
i.e. using CFNetworkHandler
and that resolves our issue but this eventually creates another issue of accessing http
URL. As we have used CFNetworkHandler
, configurations related to NSAppTransportSecurity
in info.plist
gets ignored. As Apple Developer Document says
ATS doesn’t apply to calls your app makes to lower-level networking interfaces like the Network framework or CFNetwork.
Error that we get while calling webservice with CFNetwork
is as follows and it looks like info.plist
config is getting ignored
StatusCode: 505, ReasonPhrase: 'HTTP/1.1 505 HTTP Version Not Supported', Version: 1.1, Content: System.Net.Http.CFContentStream, Headers:
{
Date: Fri, 03 Jul 2020 06:15:19 GMT
Connection: close
Server: Microsoft-HTTPAPI/2.0
Content-Type: text/html; charset=us-ascii
Content-Length: 350
}
However, on the other end,Microsoft Xamarin Says
App Transport Security does not apply to Xamarin apps using Managed HTTPClient implementations. It applies to connections using CFNetwork HTTPClient implementations or NSURLSession HTTPClient implementations only.
So, if we use NSUrlSessionHandler
the request got stuck while switching app and if we use CFNetworkHandler
then ATS won't allow to access the services.
ATS Configurations are as follows
set NSAppTransportSecurity
with NSAllowsArbitraryLoads
set to YES
set NSExceptionDomains
with following parameters
a. naaxdev.cloudapp.net
b. NSIncludesSubdomains
set to YES
c. NSExceptionAllowsInsecureHTTPLoads
set to YES
d. NSExceptionRequiresForwardSecrecy
set to NO
Upvotes: 1
Views: 298