【问题标题】:Operation timed out error操作超时错误
【发布时间】:2011-12-22 00:44:39
【问题描述】:

我在 reCaptcha.net 上碰壁了

一些背景 - 我正在使用从http://code.google.com/p/recaptcha/downloads/list?q=label:aspnetlib-Latest 获得的 reCaptcha-dotnet v1.0.5。

我能够开发一个网站并通过 reCaptcha 验证使其在本地工作。当我将它部署到服务器时(该站点托管在 1and1.com 上),我收到以下错误 -

操作已超时

描述:执行过程中发生了未处理的异常 当前的网络请求。请查看堆栈跟踪以获取更多信息 有关错误的信息以及它在代码中的来源。

异常详细信息:System.Net.WebException:操作已计时 出去

我查看了建议让服务器允许来自端口 80 的出站连接的谷歌论坛。我试图向 1and1.com 的支持人员解释这一点,但我认为他根本没有任何线索。

除了上述之外,还有什么我可以在代码方面做的事情来解决这个问题吗?有人想出解决办法吗?

感谢任何形式的建议!

【问题讨论】:

  • 您确定可以从您部署到的服务器访问recaptcha 网站吗?
  • @M.Babcock 我如何才能确认这一点?我看到了 reCaptcha 控件,所以我认为它是可访问的。

标签: c# asp.net-3.5 recaptcha


【解决方案1】:

这是我用于邮件配置和 Recaptcha 代理的代码,用于托管在 1and1 上的网站:

1- Web.config(只有放在那里才有效!)

<system.net>
    <mailSettings>
         <smtp from="mail@domain.com">
            <network host="smtp.1and1.com" port="25" userName="mymail@domain.com" password="mypassword"/>
         </smtp>
    </mailSettings>
    <defaultProxy>
        <proxy usesystemdefault = "false" bypassonlocal="false" proxyaddress="http://ntproxyus.lxa.perfora.net:3128" />
    </defaultProxy>
</system.net>

2- 在 mycontroller 的专用操作中:

// ouside the action I've defined the response
private class gapi {public bool success{get;set;}}

public bool SendMail(string firstname, string lastname, string email, string message, string grecaptcha)
{
    SmtpClient smtp = new SmtpClient("smtp.1and1.com");
    MailMessage mail = new MailMessage();
    mail.From = new MailAddress(email);
    mail.To.Add("mail@domain.com");
    mail.Subject = firstname + " " + lastname;
    mail.Body = message;
    try
    {
        using (var client = new WebClient())
        {
            var values = new NameValueCollection();
            values["secret"] = "6LcEnQYTAAAAAOWzB44-m0Ug9j4yem9XE4ARERUR";
            values["response"] = grecaptcha;
            values["remoteip"] = Request.UserHostAddress;

            var response = client.UploadValues("https://www.google.com/recaptcha/api/siteverify","POST", values);
            bool result = Newtonsoft.Json.JsonConvert.DeserializeObject<gapi>((Encoding.Default.GetString(response) as string)).success;
            if(!result) return "Something is wrong)";
        }
        //... verify that the other fields are ok and send your mail :)
        smtp.Send(mail);
    }
    catch (Exception e) { return "Something is wrong)"; }

    return "Okey :)";
}

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    终于得到了解决方案,我从 1and1 得到了正确的代理服务器地址并使用了它。 reCaptcha 现在效果很好。

    此外,由于某种原因,使用 reCaptcha 控件的 IWebProxy 属性在代码中设置代理值不起作用。我必须在 web.config 下添加标签。

    【讨论】:

    • 你添加的代理是什么?你能分享一下吗...我也面临类似的问题,试图向android发送通知....
    猜你喜欢
    • 2016-10-21
    • 1970-01-01
    • 2011-01-28
    • 1970-01-01
    • 1970-01-01
    • 2013-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多