奇怪的问题!HttpWebResponse不执行?

lxiron 2010-01-07 06:11:49
在开发环境,下面代码是执行的,可发布以后 挂到IIS,就不执行了,是不是IIS有什么限制啊 ?
            string url = "http://www.google.com";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Stream receiveStream = myHttpWebResponse.GetResponseStream();//得到回写的字节流
...全文
183 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lxiron 2010-01-08
  • 打赏
  • 举报
回复
这是获取的异常!执行到这一句就出问题了
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();


请求页面发生时间: 1/8/2010 8:52:04 AMSystem.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at ASP.global_asax.RequstMyPage(Object source, ElapsedEventArgs e) in c:\USERS\Visual Studio 2005\WebSites\ATPSystem\Global.asax:line 67

[Quote=引用 6 楼 bingo_ 的回复:]
前面的是肯定执行了 至于没有日志 那就是 receiveStream.CanRead 这个条件没有成立而已
[/Quote]
bingo_ 2010-01-07
  • 打赏
  • 举报
回复
前面的是肯定执行了 至于没有日志 那就是 receiveStream.CanRead 这个条件没有成立而已
lxiron 2010-01-07
  • 打赏
  • 举报
回复
        try
{
string url = "http://www.google.com";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Stream receiveStream = myHttpWebResponse.GetResponseStream();//得到回写的字节流
if (receiveStream.CanRead)
{
//指定日志文件的目录
string fileLogPath = AppDomain.CurrentDomain.BaseDirectory;
string fileLogName = "SoftPrj_CN_" + DateTime.Now.ToLongDateString() + "_log.txt";
//定义文件信息对象
FileInfo finfo = new FileInfo(fileLogPath + fileLogName);

//创建只写文件流
using (FileStream fs = finfo.OpenWrite())
{
//根据上面创建的文件流创建写数据流
StreamWriter strwriter = new StreamWriter(fs);
//设置写数据流的起始位置为文件流的末尾
strwriter.BaseStream.Seek(0, SeekOrigin.End);
//写入错误发生时间
strwriter.WriteLine("发生时间: " + DateTime.Now.ToString()+"执行成功!");
//写入日志内容并换行
//strwriter.WriteLine("错误内容: " + message);
strwriter.WriteLine("错误内容: ");
//写入间隔符
strwriter.WriteLine("---------------------------------------------");
strwriter.WriteLine();
//清空缓冲区内容,并把缓冲区内容写入基础流
strwriter.Flush();
//关闭写数据流
strwriter.Close();
fs.Close();
}
}
}
catch (WebException ex)
{
//指定日志文件的目录
string fileLogPath = AppDomain.CurrentDomain.BaseDirectory;
string fileLogName = "SoftPrj_CN_" + DateTime.Now.ToLongDateString() + "_log.txt";
//定义文件信息对象
FileInfo finfo = new FileInfo(fileLogPath + fileLogName);

//创建只写文件流
using (FileStream fs = finfo.OpenWrite())
{
//根据上面创建的文件流创建写数据流
StreamWriter strwriter = new StreamWriter(fs);
//设置写数据流的起始位置为文件流的末尾
strwriter.BaseStream.Seek(0, SeekOrigin.End);
//写入错误发生时间
//strwriter.WriteLine("发生时间: " + DateTime.Now.ToString() + x);
//写入日志内容并换行
//strwriter.WriteLine("错误内容: " + message);
strwriter.WriteLine("错误内容: "+ex);
//写入间隔符
strwriter.WriteLine("---------------------------------------------");
strwriter.WriteLine();
//清空缓冲区内容,并把缓冲区内容写入基础流
strwriter.Flush();
//关闭写数据流
strwriter.Close();
fs.Close();
}
}
[Quote=引用 4 楼 bingo_ 的回复:]
你是怎么写的
[/Quote]
bingo_ 2010-01-07
  • 打赏
  • 举报
回复
你是怎么写的
lxiron 2010-01-07
  • 打赏
  • 举报
回复
我写个日志文件就知道了!

[Quote=引用 2 楼 bingo_ 的回复:]
在确认支持 .net的情况下  怎么证明他没有执行
[/Quote]
bingo_ 2010-01-07
  • 打赏
  • 举报
回复
在确认支持 .net的情况下 怎么证明他没有执行
lxiron 2010-01-07
  • 打赏
  • 举报
回复
顶一下!

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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