Reputation: 296
I've developed a cross platform mobile app with Xamarin.Forms. I have local services that my app hits. My Xamarin app defines the HTTPClient as shown below. When testing on BrowserStack's App Live product I can not hit my local services from my app using the BrowserStack Local app (I receive a "No Such Host Is Known" response) . I can hit my services using the device's default browser.
HTTPClient setup in Xamarin App:
public static readonly HttpClient client = new HttpClient()
My local services have internal domain names (it's not simply 'localhost:443' but it actually has a domain name like 'customservice.com')
Is it possible for a Xamarin App to use the BrowserStack App Live product while using Local Testing? If so, how?
Upvotes: 1
Views: 1126
Reputation: 296
I found a solution that works for Android and should work for iOS (but doesn't). Maybe with some tinkering it could work for iOS too, but I thought I'd share what I found:
This step is loosely based on this article. The article is incomplete because it does not create a dependency service. So that's fun
IProxyInfoProvider
interface as shown:public interface IProxyInfoProvider
{
WebProxy GetProxySettings();
}
public class ProxyInfoProvider : IProxyInfoProvider
{
public WebProxy GetProxySettings()
{
var systemProxySettings = CFNetwork.GetSystemProxySettings();
var proxyPort = systemProxySettings.HTTPPort;
var proxyHost = systemProxySettings.HTTPProxy;
Console.WriteLine("Proxy Port: " + proxyPort.ToString());
Console.WriteLine("Proxy Host: " + Convert.ToInt64(proxyHost));
return !string.IsNullOrEmpty(proxyHost) && proxyPort != 0
? new WebProxy(proxyHost, proxyPort)
: null;
}
}
public class ProxyInfoProvider : IProxyInfoProvider
{
public WebProxy GetProxySettings()
{
var proxyHost = JavaSystem.GetProperty("http.proxyHost");
var proxyPort = JavaSystem.GetProperty("http.proxyPort");
Console.WriteLine("Proxy Host: " + proxyHost);
Console.WriteLine("Proxy Port: " + proxyPort);
return !string.IsNullOrEmpty(proxyHost) && !string.IsNullOrEmpty(proxyPort)
? new WebProxy($"{proxyHost}:{proxyPort}")
: null;
}
}
var _handler = new HttpClientHandler();
_handler.Proxy = DependencyService.Get<IProxyInfoProvider>().GetProxySettings();
Ensure that your HttpClient
is consuming this Handler in it's constructor like: new HttpClient(_handler.Value)
Upvotes: 1
Reputation: 1
Since you’re able to access your internal domain via their device browser, it seems that your application is not able to route traffic via BrowserStack’s Local Testing infrastructure.
If that is the case, you can reach out to the BrowserStack Support team for further assistance.
Upvotes: 0