2011-12-22 109 views
2

我擊中牆壁與reCaptcha.net操作超時錯誤

一些背景 - 我使用驗證碼,DOTNET V1.0.5這是我從http://code.google.com/p/recaptcha/downloads/list?q=label:aspnetlib-Latest了。

我能夠開發一個網站,並使其在reCaptcha驗證本地工作。當我將其部署到服務器(該網站託管在1and1.com),我收到以下錯誤 -

操作超時

說明:執行過程中發生未處理的異常 當前的網絡請求。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。

異常詳細信息:System.Net.WebException:操作已超時 出

我已檢查該建議有服務器的谷歌論壇允許從80端口的出站連接我試圖解釋這1and1.com的支持人員,但我不認爲他有任何線索。

除了上述內容,有什麼我可以做代碼明智解決這個問題嗎?有沒有人想出了這個解決方案?

欣賞任何形式的建議!

+0

您確定可從您部署到的服務器訪問recaptcha網站嗎? – 2011-12-22 00:59:05

+0

@ M.Babcock我如何能夠證實這一點?我看到了reCaptcha控件,所以我認爲它是可訪問的。 – Kalyan 2011-12-22 02:23:00

回答

1

終於得到了解決方案,我從1and1得到正確的代理服務器地址並使用它。 reCaptcha現在運作得很好。

此外,出於某種原因,使用reCaptcha控件的IWebProxy屬性在代碼中設置代理值不起作用。我不得不在web.config中添加標籤。

1

這是我使用的郵件配置和代理的Recaptcha爲上的1and1託管網站代碼:

1- Web.config文件(僅當把那裏的工作!)

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

2-在我的控制器中進行專門的操作:

// 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("[email protected]"); 
    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 :)"; 
} 

希望這會有所幫助。