【问题标题】:recaptcha gets invalid json from call to https://www.google.com/recaptcha/api2/userverifyrecaptcha 从调用 https://www.google.com/recaptcha/api2/userverify 获取无效 json
【发布时间】:2016-02-11 19:23:02
【问题描述】:

当recaptcha 调用https://www.google.com/recaptcha/api2/userverify?k=时

它回来了

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

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

使用 curl 时结果相同。

任何帮助将不胜感激。

【问题讨论】:

  • 你能弄清楚如何使用这个 API 吗?

标签: json recaptcha


【解决方案1】:

实际上返回的值不是有效的 json,但被 Google 的 API 很好地解析了。

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

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;`

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-08
    • 1970-01-01
    • 2020-09-16
    • 2013-12-23
    • 2012-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多