![](/img/trans.png)
[英]The remote name could not be resolved: 'www.google.com' using Recaptcha
[英]The remote name could not be resolved "www.google.com"
我在公司網絡。 在這個網絡中,我無法通過 IP ping 外部網站。 我只能像瀏覽器一樣通過 url 調用它們。 這就是我使用WebRequest 的原因。
當我嘗試撥打“www.google.com”時,出現“無法解析遠程名稱(www.google.com)”。
我的防火牆中沒有“被阻止”的條目。 使用此代碼,我可以調用內部網站,但不能調用外部網站。
這是我的代碼:
public void pingIP()
{
try
{
var url = uriBuilder;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url.Uri);
//request.Accept = "*/*";
//request.UseDefaultCredentials = true;
//request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
//request.UserAgent = "Foo";
//request.Accept = "*/*";
request.Method = "HEAD";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
_PingByURL = response.StatusCode == HttpStatusCode.OK;
}
catch
{
}
}
在 app.config 中:
<system.net>
<defaultProxy enabled ="true" useDefaultCredentials = "true">
<proxy usesystemdefault ="True" bypassonlocal="True"/>
</defaultProxy>
</system.net>
如何解析遠程名稱? 這是檢查網站是否可以通過 URL 訪問的最快速、最干凈的方法嗎?
謝謝!
這是工作沒有問題!
static void Main(string[] args)
{
Console.WriteLine(PingTest());
}
public static bool PingTest()
{
Ping ping = new Ping();
PingReply pingStatus = ping.Send(IPAddress.Parse("208.69.34.231"));
//For the web address you need !
//PingReply pingStatus = ping.Send("www.google.com");
return pingStatus.Status == IPStatus.Success;
}
可能存在網絡限制,而您因此而失敗。
public bool ConnectedToInternet()
{
var myPing = new Ping();
const string host = "google.com";
var buffer = new byte[32];
const int timeout = 1000;
var pingOptions = new PingOptions();
var reply = myPing.Send(host, timeout, buffer, pingOptions);
return reply != null && reply.Status == IPStatus.Success;
}
試試這個,讓我知道你是否得到回復
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.