gpt4 book ai didi

c# - 操作超时错误

转载 作者:太空宇宙 更新时间:2023-11-03 14:08:28 26 4
gpt4 key购买 nike

我在 reCaptcha.net 上碰壁了

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

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

The operation has timed out

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The operation has timed out

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

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

感谢任何建议!

最佳答案

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

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 :)";
}

希望这对您有所帮助。

关于c# - 操作超时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8598185/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com