HTTP Client Problem in Xamarin Forms :
-Problem: Many times HttpClient in PCL Project not working it's give exception if your URL is like:"https" or Your URL is not secure.
- Solution:
1. You can manage your native HttpMessageHandler
Android:
Right click on Android Project -->Properties-->Android Option
Click On Advanced -->
Select "Android" from HttpClient Implementation DropDown
Select "SSL/TLS" from SSL/TLS implementation dropdown
iOS:
Right Click on ios Project->Properties
Select Native HttpClient Handler from HttpClient implementation dropdown
2. You can use dependency Service to use native HttpMessageHandler
- Create Interface in PCL Project :
public interface IHttpHandler{
object GetHttpHandler();
}
- Create class in android and iOS project for Interface implementation:
Android:
public class HttpHandlerImp : IHttpHandler
{
public object GetHttpHandler()
{
var handler = new AndroidClientHandler();
return handler;
}
}
iOS:
public class HttpHandlerImp : IHttpHandler
{
public object GetHttpHandler()
{
var nsUrlSession = new NSUrlSessionHandler();
return nsUrlSession;
}
}
HttpClient Handler with Dependency Service:
var handler=(System.Net.Http.HttpMessageHandler)DependencyService.Get<IHttpHandler>().GetHttpHandler();
HttpClient client = new HttpClient(handler);
-Problem: Many times HttpClient in PCL Project not working it's give exception if your URL is like:"https" or Your URL is not secure.
- Solution:
1. You can manage your native HttpMessageHandler
Android:
Right click on Android Project -->Properties-->Android Option
Click On Advanced -->
Select "Android" from HttpClient Implementation DropDown
Select "SSL/TLS" from SSL/TLS implementation dropdown
iOS:
Right Click on ios Project->Properties
Select Native HttpClient Handler from HttpClient implementation dropdown
2. You can use dependency Service to use native HttpMessageHandler
- Create Interface in PCL Project :
public interface IHttpHandler{
object GetHttpHandler();
}
- Create class in android and iOS project for Interface implementation:
Android:
public class HttpHandlerImp : IHttpHandler
{
public object GetHttpHandler()
{
var handler = new AndroidClientHandler();
return handler;
}
}
iOS:
public class HttpHandlerImp : IHttpHandler
{
public object GetHttpHandler()
{
var nsUrlSession = new NSUrlSessionHandler();
return nsUrlSession;
}
}
HttpClient Handler with Dependency Service:
var handler=(System.Net.Http.HttpMessageHandler)DependencyService.Get<IHttpHandler>().GetHttpHandler();
HttpClient client = new HttpClient(handler);
HTTP Client Problem in Xamarin Forms
Reviewed by Dev Tech Solution
on
November 28, 2018
Rating:
Thanks
ReplyDeleteDid you hear there's a 12 word sentence you can communicate to your crush... that will induce deep emotions of love and impulsive appeal to you buried inside his chest?
ReplyDeleteBecause hidden in these 12 words is a "secret signal" that fuels a man's instinct to love, treasure and look after you with his entire heart...
12 Words Will Trigger A Man's Love Instinct
This instinct is so built-in to a man's brain that it will make him work better than before to make your relationship as strong as it can be.
Matter of fact, triggering this influential instinct is absolutely binding to getting the best ever relationship with your man that as soon as you send your man one of the "Secret Signals"...
...You'll instantly notice him open his mind and soul for you in such a way he haven't expressed before and he will distinguish you as the one and only woman in the world who has ever truly understood him.