能够获在C#取访问的页面的响应时间,是不是能够正常访问.
是怎么一个思路的啊?
谢谢

解决方案 »

  1.   

    不用代理的话把proxyObject去掉 //GetPageRight方法定义
    public static bool GetPageRight(String url, WebProxy proxyObject, out string ret_str) 
    {
    string proxy_str="null";
    ret_str=url+":未知错误";
    try 
    {   
    // Creates an HttpWebRequest for the specified URL. 
    HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
    myHttpWebRequest.Proxy =proxyObject;
    if(proxyObject.Address!=null)proxy_str=proxyObject.Address.ToString(); 

    // Sends the HttpWebRequest and waits for a response.
    HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 
    if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
    ret_str=":返回正确,通过代理: "+proxy_str+" : "+url+" :返回代码为 OK 且返回状态描述为: "+myHttpWebResponse.StatusDescription;
    // Releases the resources of the response.
    myHttpWebResponse.Close(); 
    return true;
             

    catch(WebException e) 
    {
    ret_str=":出现Web错误,通过代理: "+proxy_str+" : "+url+" :发生Web异常! 错误代码如下 : "+e.Status.ToString(); 
    }
    catch(Exception e)
    {
    ret_str=":出现未知错误,通过代理: "+proxy_str+" : "+url+" :错误代码如下 : "+e.Message;
    } return false;
    }