简体   繁体   中英

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. 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. 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.

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. I am currently using the .NET 4.0 Client package if this is potentially causing any issues. the only error that I get is a timeout error with 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? 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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