简体   繁体   English

C#调用URL:超时

[英]C# Calling a URL: Timeout

I am trying to write a part of a program that notifies the Admin that a clients data has been updated/sent by calling a URL that sends an email to the admin. 我正在尝试编写程序的一部分,该程序通过调用将电子邮件发送给管理员的URL来通知管理员已更新/发送了客户端数据。 I have been successful in doing this but only on Windows 7 and 2003. I need it to run on Windows server 2008. It also needs to this by hiding the web browser from the user when the url is called. 我已成功完成此操作,但仅在Windows 7和2003上成功。我需要它在Windows Server 2008上运行。它也需要在调用url时向用户隐藏Web浏览器。 I have been successful in sending the email if I let the explorer window open but if I try and hide the window it always fails. 如果我打开浏览器窗口,则可以成功发送电子邮件,但是如果我尝试隐藏该窗口,则它总是会失败。 The code I am using is as follows: 我使用的代码如下:

HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url += strNewValue);
// execute the request
HttpWebResponse response = (HttpWebResponse)wr.GetResponse();

Stream resStream = response.GetResponseStream();
    response.Close();

/*   
    WebBrowser web = new WebBrowser();
        web.AllowNavigation = true;
        web.Visible = false;
        web.Navigate(url+strNewValue);
*/
/*
    ProcessStartInfo startweb = new ProcessStartInfo(url + strNewValue);
        startweb.RedirectStandardOutput = false;
        startweb.WindowStyle = ProcessWindowStyle.Hidden;
        startweb.UseShellExecute = true;
        startweb.CreateNoWindow = true;

        Process.Start(startweb);
*/

The commented code is showing the other attempts that I have tried to make this work. 注释的代码显示了我为使这项工作努力的其他尝试。 This code all seem to work successfully on Windows 2007 and Windows Server 2003 but I cannot get it to work on Windows 2008 Server which is a must. 这段代码似乎都可以在Windows 2007和Windows Server 2003上成功运行,但是我无法在必须的Windows 2008 Server上运行。

Every time it gets to this section of the code in the application, the program starts to NOT RESPOND, eventually recovers and says that it has sent the notification. 每当它到达应用程序中的代码这一部分时,该程序便开始不响应,最终恢复并说它已发送了通知。 However, it freezes at this point in the application and the email is never sent. 但是,它此时在应用程序中冻结,并且永远不会发送电子邮件。 I have checked this URL and it sends the email without any issues when done manually. 我已经检查了该URL,并且手动完成后它发送电子邮件没有任何问题。 I am currently using the .NET 4.0 Client package if this is potentially causing any issues. 我目前正在使用.NET 4.0客户端软件包,如果这可能引起任何问题。 the only error that I get is a timeout error with httpwebresponse getresponse(); 我得到的唯一错误是httpwebresponse getresponse()的超时错误;

Any advice would be extremely helpful. 任何建议都将非常有帮助。 Thank you in advance 先感谢您

Can you instead configure the objects from the System.Net.Mail namespace such as SmtpClient and send the e-mail directly yourself? 您是否可以改为从System.Net.Mail命名空间(如SmtpClient配置对象,然后直接自己发送电子邮件? This solution introduces a seemingly unnecessary and complex/prone to failure process into sending an e-mail, which is a fairly trivial task to do programmatically. 此解决方案在发送电子邮件时引入了看似不必要和复杂/易于失败的过程,这是通过编程进行的相当琐碎的任务。

SmtpClient MSDN Documentation SmtpClient MSDN文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM