WebRequest问题?

amagic 2003-08-22 04:32:45
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
nameSpace TestIMDb{

Class Class1{
static void Main(string[] args)
{
string strImdbResult = null;
Encoding strEncode = System.Text.Encoding.GetEncoding("UTF-8");
try
{
WebRequest wreq = WebRequest.Create("http://www.imdb.com");
WebResponse wres = wreq.GetResponse();
StreamReader sr = new StreamReader(wres.GetResponseStream(), strEncode);
strImdbResult = sr.ReadToEnd();

string strFile = "result.html";
StreamWriter sw = File.CreateText(strFile);
sw.Write(strImdbResult);
sw.WriteLine();
sw.Close();

DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory);
string strFilePath = di.FullName + "\\" + strFile;

System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = "iexplore.exe";
myProcess.StartInfo.Arguments = strFilePath;
myProcess.Start();
}
catch( WebException e )
{
Console.WriteLine( "IMDB :" + e.Message );
}
catch( Exception e )
{
Console.WriteLine( "IMDB :" + e.Message );
}

}
}
}


请各位测试一下这段代码,我总是得到403 Fobidden的异常,而只要把www.imdb.com改为其他的网址如www.google.com等就可以,不知道这是为什么?应该不是imdb网站的问题,因为我朋友用java可以对它做同样的操作。
...全文
25 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
dahuzizyd 2003-08-22
  • 打赏
  • 举报
回复
再测还是好的。
jjcccc 2003-08-22
  • 打赏
  • 举报
回复
再测,又不行了,是不是那个网站不稳定,或我们出口的忘络不稳定?
dahuzizyd 2003-08-22
  • 打赏
  • 举报
回复
奇怪,你的代码我试了,开始确实是报错,但是到那个网站上去了一次,然后就好了,???
amagic 2003-08-22
  • 打赏
  • 举报
回复
我还是不行:(
jjcccc 2003-08-22
  • 打赏
  • 举报
回复
忘了说了,我把http://www.imdb.com改成了@"http://www.imdb.com"。但应该没有影响。
jjcccc 2003-08-22
  • 打赏
  • 举报
回复
再测试,又可以了。你最测试看,最好把http://www.imdb.com删掉重写一遍。注意:不要是汉字的:。
jjcccc 2003-08-22
  • 打赏
  • 举报
回复
测试,果然如此。继续研究

110,566

社区成员

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

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

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