Xamarin WatchOS System.Net.HttpWebRequest not supported

Do you have a solution on the Apple WatchOS that uses the NSUrlSession or similar instead of the System.Net.HttpWebRequest like it is in the WinInetHttpClientChannel? The System.Net.HttpWebRequest is not supported on the watch. It works fine on the the iPhone. This is strictly an iOS project using Xamarin.

Hello

Please take a look at this client channel: HttpClient-based Client Channel for Xamarin platforms (and other platforms supported via PCL)

It is HttpClient-based so ther should be no issues on Watch.

Regards

I had tried that already but got this exception: System.Net.Http.HttpClientHandler is not supported on the current platform. I uploaded two files, one that shows the HttpClientHandler as it appears in the assembly browser in the iOS project and one as it appears in the watchOS project.
HttpClientHandler - iOS.cs (9.9 KB)
HttpClientHandler - WatchOS.cs (8.8 KB)

That’s odd because according to this: https://forums.xamarin.com/discussion/88475/watchos-web-api-call HttpClient doesn’t throw PlatformNotSupported exceptions.

Abyway, you can try this library: https://github.com/paulcbetts/ModernHttpClient . It is based on NSURLSession so it should work even on watchOS .

The System.Net.HttpClientHandler wasn’t supported on the watch but the NSUrlSessionHandler is. I added the System.Net.Http nuget package and the file you mentioned in your first post. It didn’t work until I modified it like this:

//protected virtual HttpClientHandler CreateHttpHandler(bool usesAuthentication, string username, string password)
//{
//	HttpClientHandler handler = new HttpClientHandler();
//	handler.AllowAutoRedirect = AllowAutoRedirect;
//	if (usesAuthentication)
//	{
//		handler.Credentials = new NetworkCredential(username, password);
//	}
//
//	return handler;
//}

protected virtual NSUrlSessionHandler CreateHttpHandler (bool usesAuthentication, string username, string password)
{
	var handler = new NSUrlSessionHandler ();
	handler.AllowAutoRedirect = AllowAutoRedirect;
	if (usesAuthentication) {
		handler.Credentials = new NetworkCredential (username, password);
	}

	return handler;
}

So now it works? Could you also add your solution for watchOS to the snippet thread too?

Yes it works. I am communicating with our app server using an aes encrypted binary channel.

I uploaded the file here.

I had watchOS communicating but when I tried to upload the app to the app store it got rejected because the size was too large for a watch app. I ended up removing all of remobjects from the watch to get the size down so I could post it to the store. I tried turning the linker to all and removing any other dependencies but it didn’t make it small enough. The limit for a watchOS app is 50 MB. If anybody has a suggestion to make it work size-wise I would like to hear it.