我在使用HttpClient
方法
我正在使用 我的代码下面工作正常当我把网址“google.com”放在我给我的网络服务网址时它不起作用我想在我的网址中包含端口号我该如何实现呢
if (CrossConnectivity.Current.IsConnected)
{
bool isRemoteReachable = await CrossConnectivity.Current.IsReachable("192.168.1.107",3);
if (!isRemoteReachable)
{
await DisplayAlert("Server not available", "Please try again later", "OK");
}
}
答案 0 :(得分:1)
根据official connectivity plugin documentation设置端口,您应该以下一种方式调用该方法:
/// <summary>
/// Tests if a remote host name is reachable (no http:// or www.)
/// </summary>
/// <param name="host">Host name can be a remote IP or URL of website</param>
/// <param name="port">Port to attempt to check is reachable.</param>
/// <param name="msTimeout">Timeout in milliseconds.</param>
/// <returns></returns>
Task<bool> IsRemoteReachable(string host, int port = 80, int msTimeout = 5000);
或内部主持人:
/// <summary>
/// Tests if a host name is pingable
/// </summary>
/// <param name="host">The host name can either be a machine name, such as "java.sun.com", or a textual representation of its IP address (127.0.0.1)</param>
/// <param name="msTimeout">Timeout in milliseconds</param>
/// <returns></returns>
Task<bool> IsReachable(string host, int msTimeout = 5000);
我认为应该将其翻译成:
IsReachable("192.168.1.107:8733", 30 * 1000);
注意msTimeout,你有3ms的值,增加它,否则方法可能几乎立即返回,结果为负。
编辑:
经过简短的聊天,结果证明这是一个特定于图书馆的问题。我建议您自己编写ping方法或者向连接插件github页面提交错误。