【发布时间】:2015-04-08 14:35:40
【问题描述】:
你能帮帮我吗?我正在尝试获取任何网页的内容。但 GetResponse 不断抛出未找到的异常页面。我感谢您的帮助。以下是我的代码。
try
{
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.smallchiptechnologies.com/");
request.Method = "POST";
request.ContentType = "text/plain";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
}
【问题讨论】:
-
为什么要使用
POST来获取网页的内容?POST用于向服务器发送数据,例如表单输入。要获取页面内容,您必须使用GET -
感谢托马斯的回复。我将 POST 更改为 GET 但没有运气。我也做了 Ulugbek 建议的事情,比如添加 contentLength。您认为这可能是网络问题吗?
-
您得到的确切异常是什么?
-
System.Net.WebException:远程服务器返回错误:(404)未找到。在 System.Net.HttpWebRequest.GetResponse() 在 Translate.TranslateText.Program.Main(String[] args)
-
@Tom 您是否提供了您尝试从中获取数据的实际页面地址?它可以在我的计算机上在浏览器和 c# 代码中完美运行,而不会出现 404。您可以在浏览器中打开您尝试访问的页面吗?
标签: c# visual-studio-2013 webpage web-access