【问题标题】:Capturing html code from a website - The remote server returned an error: (407) Proxy Authentication Required从网站捕获 html 代码 - 远程服务器返回错误:(407) 需要代理身份验证
【发布时间】:2011-01-18 16:33:23
【问题描述】:

我想从页面中捕获 HTML 代码并将其放入文本文件中。不幸的是,我收到以下错误:

“远程服务器返回错误:(407) 需要代理身份验证。”

有人知道怎么解决吗?

    string url = @"http://www.panalpina.com/www/global/en/tools_resources/unit_converter/currency_codes.html";
    HttpWebRequest myWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
    myWebRequest.Method = "GET";
    // make request for web page
    myWebRequest.ToString();


    HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse();
    StreamReader myWebSource = new StreamReader(myWebResponse.GetResponseStream());
    string myPageSource = string.Empty;
    myPageSource = myWebSource.ReadToEnd();
    myWebResponse.Close();


    ` 

【问题讨论】:

    标签: c# httpwebrequest httpwebresponse


    【解决方案1】:

    您似乎正在使用代理服务器连接到互联网。 如果是,则在发送 http 请求之前添加下一个代码:

    myWebRequest.Proxy = new WebProxy("you_proxy_machine", 8080 /*port*/);
    myWebRequest.Proxy.Credentials = new NetworkCredential("proxy_username", proxy_password");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多