c# - Recaptcha.Net connection error with proxy -


i developing enterprise system using asp.net mvc 5. there have registration action captcha powered recaptchanet library nuget works google recaptcha.

now, have encountered problem. that's beginning of registration action:

[httppost] [validateantiforgerytoken] public async task<jsonresult> register(registerviewmodel model) {     try     {         recaptchaverificationhelper recaptchahelper = this.getrecaptchaverificationhelper();         if (string.isnullorempty(recaptchahelper.response))         {             // return error         }          recaptchaverificationresult recaptcharesult = await recaptchahelper.verifyrecaptcharesponsetaskasync();         if (recaptcharesult != recaptchaverificationresult.success)         {             // return error         } 

at line

recaptchaverificationresult recaptcharesult = await recaptchahelper.verifyrecaptcharesponsetaskasync(); 

i following exception:

exception text (depth 0): unable connect remote server @ recaptcha.web.recaptchaverificationhelper.<verifyrecaptcharesponsetaskasync>b__0() @ system.threading.tasks.task1.innerinvoke() @ system.threading.tasks.task.execute() --- end of stack trace previous location exception thrown --- @ system.runtime.compilerservices.taskawaiter.throwfornonsuccess(task task) @ system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification(task task) @ system.runtime.compilerservices.taskawaiter1.getresult() @ bankingclient.controllers.accountcontroller.<register>d__8.movenext() in c:\src\ibrc-svn\webclients\bankingclient\controllers\accountcontroller.cs:line 152  exception text (depth 1): no connection made because target machine actively refused 88.204.142.34:443 @ system.net.sockets.socket.doconnect(endpoint endpointsnapshot, socketaddress socketaddress) @ system.net.servicepoint.connectsocketinternal(boolean connectfailure, socket s4, socket s6, socket& socket, ipaddress& address, connectsocketstate state, iasyncresult asyncresult, exception& exception) 

after seaching answer @ stackoverflow, have understood problem use proxy. have decompiled recaptchanet library dotpeek of resharper , here code:

public task<recaptchaverificationresult> verifyrecaptcharesponsetaskasync() {     // code     byte[] bytes = encoding.ascii.getbytes(string.format("privatekey={0}&remoteip={1}&challenge={2}&response={3}", (object) recaptchakeyhelper.parsekey(this.privatekey), (object) this.userhostaddress, (object) this._challenge, (object) this.response));     uri requesturi = this.usessl ? new uri("https://www.google.com/recaptcha/api/verify", urikind.absolute) : new uri("http://www.google.com/recaptcha/api/verify", urikind.absolute);      httpwebrequest httpwebrequest = (httpwebrequest)webrequest.create(requesturi);     httpwebrequest.contenttype = "application/x-www-form-urlencoded";     httpwebrequest.contentlength = (long)bytes.length;     httpwebrequest.method = "post";     iwebproxy systemwebproxy = webrequest.getsystemwebproxy();     systemwebproxy.credentials = credentialcache.defaultcredentials;     httpwebrequest.proxy = systemwebproxy;     httpwebrequest.getrequeststream().write(bytes, 0, bytes.length);     httpwebresponse httpwebresponse = (httpwebresponse)httpwebrequest.getresponse();     string[] strarray = (string[])null;     using (streamreader streamreader = new streamreader(httpwebresponse.getresponsestream()))         strarray = streamreader.readtoend().split('\n'); 

now, copy code own class in empty console application:

byte[] bytes = encoding.ascii.getbytes("check"); uri requesturi = new uri("https://www.google.com/recaptcha/api/verify", urikind.absolute);  httpwebrequest httpwebrequest = (httpwebrequest)webrequest.create(requesturi); httpwebrequest.contenttype = "application/x-www-form-urlencoded"; httpwebrequest.contentlength = (long)bytes.length; httpwebrequest.method = "post"; iwebproxy systemwebproxy = webrequest.getsystemwebproxy(); systemwebproxy.credentials = credentialcache.defaultcredentials; httpwebrequest.proxy = systemwebproxy; httpwebrequest.getrequeststream().write(bytes, 0, bytes.length); httpwebresponse httpwebresponse = (httpwebresponse)httpwebrequest.getresponse(); string[] strarray = (string[])null; using (streamreader streamreader = new streamreader(httpwebresponse.getresponsestream()))     strarray = streamreader.readtoend().split('\n'); 

and works. spent bunch of time trying understand going wrong. if can affect something, have activedirectory authentication everywhere in organization including proxy authentication.


Comments