• 全部
  • C#综合技术
  • C#互联网桌面应用
  • AppLauncher
  • WinForm&WPF
  • C#开发新技术
  • 问答

关于网络方面的问题

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
)
最好给出网络编程方面的学习资料
...全文
79 点赞 收藏 9
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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
回复
相关推荐
发帖
C#
创建于2007-09-28

10.5w+

社区成员

.NET技术 C#
申请成为版主
帖子事件
创建了帖子
2004-10-30 12:45
社区公告

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