recaptcha从对https://www.google.com/recaptcha/api2/userverify的调用中获取无效的json [英] recaptcha gets invalid json from call to https://www.google.com/recaptcha/api2/userverify

查看:227
本文介绍了recaptcha从对https://www.google.com/recaptcha/api2/userverify的调用中获取无效的json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当recaptcha呼叫 https://www.google.com/recaptcha /api2/userverify?k =

When recaptcha makes the call to https://www.google.com/recaptcha/api2/userverify?k=

它又回来了

)]}' ["uvresp" ,,,, 2]

)]}' ["uvresp",,,,2]

授予有效的k后,还会返回更多.但是)]}'显然是无效的json. 当我尝试使用grecaptcha.getResponse()检索响应时,我得到一个空字符串.

Granted with a valid k it comes back with a bit more. However the )]}' is clearly invalid json. When I try to retrieve the response with grecaptcha.getResponse() I get an empty string.

使用curl时,结果相同.

Same result when using curl.

任何帮助将不胜感激.

推荐答案

实际上,返回的值不是有效的json,但可以通过Google API很好地解析.

Actually the value returned is not valid json but well parsed by the Google's API.

这是保护吗?我不知道,但是如果您看一下javascript,就会发现:

Is it a protection ? I don't know, but if you look at the javascript, you can find that:

var jm=function(a,b,c,d,e,g,h,l,r){this.xl=a;this.$c=c||"GET";this.Ka=d;this.Gg=e||null;this.Td=m(h)?h:1;this.ye=0;this.xh=this.Nh=!1;this.uh=b;this.Mh=g;this.md=l||"";this.Zb=!!r;this.Wf=null};f=jm.prototype;f.getUrl=function(){return this.xl};f.ug=function(){return this.$c};f.Ca=function(){return this.Ka};f.fi=function(){return this.Zb};f.bi=function(){return this.md};var nm=function(){G.call(this);this.nj=new hm(0,mm,1,10,5E3);H(this,this.nj);this.ad=0};x(nm,G);var mm=new Nh;nm.prototype.send=function(a){return new Lc(function(b,c){var d=String(this.ad++);this.nj.send(d,a.Uf.toString(),a.ug(),a.Ca(),mm,void 0,u(function(a,d){var h=d.target;if(Xk(h)){var l=a.ml;h.B?(h=h.B.responseText,0==h.indexOf(")]}'\n")&&(h=h.substring(5)),h=Hg(h)):h=void 0;b(new l(h))}else c(new om(a))},this,a))},this)};var om=function(a){y.call(this);this.request=a};x(om,y);

特别是看看:

var l=a.ml;h.B?(h=h.B.responseText,0==h.indexOf(")]}'\n")&&(h=h.substring(5)),h=Hg(h)):h=void 0;`

解析器显式检查该值是否以)]}开头并剥离它.

The parser explicitly checks that the value begins by )]} and strips it.

我建议您只在"json" 字符串上应用相同的子字符串

I suggest you to just apply the same substring on the "json" string

这篇关于recaptcha从对https://www.google.com/recaptcha/api2/userverify的调用中获取无效的json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆