iphone(xamarin.ios)手机网络的互联网连接返回false
以下代码在检查设备上的蜂窝(wwan)网络时返回true(wifi连接),但返回false(假), 这是密码iphone(xamarin.ios)手机网络的互联网连接返回false,ios,xamarin.ios,monodevelop,xamarin,internet-connection,Ios,Xamarin.ios,Monodevelop,Xamarin,Internet Connection,以下代码在检查设备上的蜂窝(wwan)网络时返回true(wifi连接),但返回false(假), 这是密码 试试看 { HttpWebRequest请求=(HttpWebRequest)WebRequest.Create(“http://www.google.com"); 请求超时=25000; request.Credentials=CredentialCache.DefaultNetworkCredentials; request.UseDefaultCredentials=true; H
试试看
{
HttpWebRequest请求=(HttpWebRequest)WebRequest.Create(“http://www.google.com");
请求超时=25000;
request.Credentials=CredentialCache.DefaultNetworkCredentials;
request.UseDefaultCredentials=true;
HttpWebResponse=(HttpWebResponse)request.GetResponse();
返回response.StatusCode==HttpStatusCode.OK;
}
捕获(例外e)
{
返回false;
}
我得到的错误如下
远程服务器返回错误:(403)禁止
帮助。查看Xamarin可达性类 编辑:
从下载并安装沃达丰配置文件,您可以使用Reachibility
#import "Reachability.h"
+(bool)internetConnection
{
Reachability* reachability;
reachability = [Reachability reachabilityWithHostname:@"www.google.com"];
NetworkStatus netStatus = [reachability currentReachabilityStatus];
[reachability startNotifier];
switch (netStatus)
{
case NotReachable:
{
//[self showLoadingView:@"Internet Unavailable!!"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"NetworkFail" object:self];
return NO;
break;
}
case ReachableViaWWAN:
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"NEtworkPass" object:self];
return YES;
break;
}
case ReachableViaWiFi:
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"NEtworkPass" object:self];
return YES;
break;
}
}
}如果您尝试连接到其他站点,是否会得到相同的结果?您的运营商是否使用了干扰您连接的代理?如果蜂窝网络不工作,您不会收到403错误。403来自服务器(因此请求通过了)。其他内容(配置、VPN、代理…)正在阻止你。@Jason:是的,所有其他站点都返回相同的结果。@poupou:那么我们怎么知道。我们应该怎么做才能克服它?在模拟器上运行良好…让我检查真实设备。在wifi网络上运行,但不在蜂窝数据上运行。如果你仍然收到403错误,那么@poupou是真的。激活你的蜂窝数据网络。我想要它适用于Xamarin版本。