关于网络方面的问题

byebye8741 2004-10-30 12:45:57
各位看看实现以下功能的语句是什么?
通过一个地址去浏览一个地址(网站不需要显示出来)
如果正常显示这个网站的话就显示“正常”
(http://www.donghualvyou.com/detail/detail.asp?id=751)
如果无法找到文件(404错误)就显示“无法找到文件”
(http://www.donghualvyou.com/detail/detail1.asp?id=751)
如果其他错误则显示出错误信息
(比如http://www.donghualvyou.com/detail/detail.asp?id=751111则显示
ADODB.Field error '800a0bcd'

Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

/detail/detail.asp, line 10
)
最好给出网络编程方面的学习资料
...全文
170 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ych1 2004-10-30
  • 打赏
  • 举报
回复
微软的MSDN里面就有,详情见 .NET Framework 类库

HttpStatusCode 枚举
jackie615 2004-10-30
  • 打赏
  • 举报
回复
up
byebye8741 2004-10-30
  • 打赏
  • 举报
回复
没有人?
xiaoslong 2004-10-30
  • 打赏
  • 举报
回复
帮你顶
byebye8741 2004-10-30
  • 打赏
  • 举报
回复
不是这个意思
我的意思是
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.donghualvyou.com/detail/detail.asp?id=751");
try
{
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Stream receiveStream = myHttpWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("GB18030");
StreamReader readStream = new StreamReader( receiveStream, encode );
this.richTextBox1.Text=readStream.ReadToEnd();
myHttpWebResponse.Close();
readStream.Close();
}
catch(System.Net.WebException aa)
{
this.richTextBox1.Text=aa.Message;
}

这段代码在显示正确的时候能够显示源代码但是500错误的时候只是显示500错误也就是HTTPP友好错误信息,我怎么能得到实际得错误信息,也就是关闭了HTTP友好错误信息时候的东西呢
比如ADODB.Field error '800a0bcd'

Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

/detail/detail.asp, line 10
happyjun2000 2004-10-30
  • 打赏
  • 举报
回复
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.donghualvyou.com/detail/detail.asp?id=751'");

如果需要用户名和密码等登陆以后才可以访问的地址
参考--
利用HttpRequest登录到某个网站,然后获取网站信息的程序示例:
http://news.dvbbs.net/infoview/Article_2776.html


利用CookieContainer类实现
byebye8741 2004-10-30
  • 打赏
  • 举报
回复
说明白了就是
catch(System.Net.WebException aa)
{
this.richTextBox1.Text+=aa.Message;


}
这个只显示内部服务器599错误而不是显示关闭了HTTP友好信息的
ADODB.Field error '800a0bcd'

Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

/detail/detail.asp, line 10
byebye8741 2004-10-30
  • 打赏
  • 举报
回复
关键是要显示错误类型而不是简单的500错误

HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.donghualvyou.com/detail/detail.asp?id=751'");
// Sends the HttpWebRequest and waits for the response.

try
{
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Stream receiveStream = myHttpWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader( receiveStream, encode );
this.richTextBox1.Text+="\r\nResponse stream received.";
Char[] read = new Char[256];
// Reads 256 characters at a time.
int count = readStream.Read( read, 0, 256 );
this.richTextBox1.Text+="HTML...\r\n";
while (count > 0)
{
// Dumps the 256 characters on a string and displays the string to the console.
String str = new String(read, 0, count);
this.richTextBox1.Text+=str;
count = readStream.Read(read, 0, 256);
}

// Releases the resources of the response.
myHttpWebResponse.Close();
// Releases the resources of the Stream.
readStream.Close();
}
catch(System.Net.WebException aa)
{
this.richTextBox1.Text+=aa.Message;

}

// Gets the stream associated with the response.


这样的代码只会显示500错误
jackie615 2004-10-30
  • 打赏
  • 举报
回复
学习 友情UP

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧