c# - 无法使用 WebResponse c# 访问此页面

标签 c# asp.net

我正在尝试访问此页面: http://tawn.tnau.ac.in/General/BlockWiseSummaryPublicUI.aspx?EntityHierarchyOneKey=1&lang=en 代码如下:

String strResult;
WebResponse objResponse;
WebRequest objRequest = System.Net.HttpWebRequest.Create(strURL);

objResponse = objRequest.GetResponse();
// the using keyword will automatically dispose the object 
// once complete
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
   strResult = sr.ReadToEnd();
   // Close and clean up the StreamReader
   sr.Close();
}

访问其他页面时工作正常。我尝试使用 Mozila 访问此页面,但在 Chrome 上运行时无法访问。

请让我知道解决方案。

提前致谢

最佳答案

问题与浏览器无关。你的代码应该可以正常工作。但是,当您提出请求时,您可能需要提供一些凭据才能访问该页面。

如果您不提供凭据,请求通常会被重定向到一个页面,这就是您的情况。

关于c# - 无法使用 WebResponse c# 访问此页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20628206/

相关文章:

c# - 将文本与文本框的一部分对齐

c# - ParallelQuery 核心平衡

asp.net - 使用 moq 模拟 HttpMessageHandler - 如何获取请求的内容?

asp.net - 如何在 ASP.NET MVC 中存储信息 "per browser tab"?

c# - IIS 上 ASP.NET 页面的 Restful URL

c# - 对象无法序列化,因为它没有无参数构造函数

c# - 命令行解析器库 - bool 参数

c# - multi.Read 的输出参数始终为 null

c# - 旋转 [Win32Exception (0x80004005) : Access is denied]

javascript - 如何让 javascript eval 返回字符串而不是变量?