Imports System.Text
Imports System.Net
Imports System.IO Public Shared Function GetDate(ByVal strUrl As String) As String
        Dim html As String = ""
        Try
            Dim resp As HttpWebResponse
            Dim req As HttpWebRequest = CType(HttpWebRequest.Create(strUrl), HttpWebRequest)
            req.Timeout = 250000
            resp = CType(req.GetResponse(), HttpWebResponse)
            Dim sr As StreamReader = New StreamReader(resp.GetResponseStream(), System.Text.Encoding.Default)
            html = "访问成功返回代码如下:" & sr.ReadToEnd()
        Catch ex As Exception
            html = "错误:" & ex.Message
        End Try
        Return html
    End Function

解决方案 »

  1.   

    这样:
    using System.Net;string url=".........";//网址
    try
    {
    Uri uri=new Uri(url);
    System.Net.Dns.Resolve(uri.Host);
    }
    catch(Exception ex)
    {
    string msg=ex.Message;
    }另上面的转换为c#如下:
    public string GetDate(string strUrl)
    {
    string html="";
    try
    {
    System.Net.HttpWebRequest req=System.Net.HttpWebRequest.Create(strUrl);
    req.Timeout =250000;
    System.Net.HttpWebResponse resp=req.GetResponse();
    System.IO.StreamReader sr=new System.IO.StreamReader(resp.GetResponseStream(),System.Text.Encoding.Default);
    html ="访问成功返回代码如下:" & sr.ReadToEnd();
    }
    catch(Exception ex)
    {
    html ="错误:" & ex.Message;
    }
    return html;
    }