【发布时间】:2020-04-05 15:37:54
【问题描述】:
所以我有一些代码可以访问网站的 html,因为它可以正常工作,但仅在 c# 的 visualstudios.Framework 中,当此代码输入 app.config 时。
<system.net> <defaultProxy useDefaultCredentials="true" /> </system.net>
ps 之间的下一行 >
但我需要此代码在 .CORE 而不是 .FRAMEWORK 中工作 但它给出了这个错误。
System.Net.WebException:'远程服务器返回错误:(407)需要代理身份验证。'
我尝试通过从解决方案资源管理器创建 app.config 来解决它,但它没有任何影响 互联网上的所有答案要么太复杂,要么表明我在 .FRAMEWORK 的 app.config 中放入的一小段代码在 .Core 上不起作用
代码作为起点。
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddress);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = null;
if (response.CharacterSet == null)
{
readStream = new StreamReader(receiveStream);
Console.WriteLine("Sorry , somethings faulty");
}
else
{
readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
readStream.ToString();
// Console.WriteLine(readStream);
}
string ImpureTexta = readStream.ReadToEnd().ToString();
BaseHTML = ImpureTexta; ///turns ImpureText in class to the actual html code so it can be used by entire program
Console.WriteLine(BaseHTML);
Console.WriteLine(" <--------------------------------Extraction B Complete --------------------------------->");
}
谢谢
【问题讨论】:
标签: c# .net-core system.net.webexception webexception