不正确的身体内容ngx.location.capture

时间:2015-10-01 14:23:45

标签: curl nginx lua recaptcha

我想使用lua + nginx

检测正确的Google验证码数据(API2)

我想使用ngx.location.capture函数。

Nginx配置(派对):

location = /recaptcha/api/siteverify {
        resolver   8.8.8.8;
        proxy_pass https://www.google.com;
        }

lua代码的一部分:

local res = ngx.location.capture("/recaptcha/api/siteverify", {method = ngx.HTTP_POST,args ={ secret = "<MY_SECRET_KEY>", response = resp, remoteip = ip} })

在这种情况下,我收到了错误的'二进制'res.body数据:

["�RPP*.MNN-.V�R()*M��

或在nginx日志中:

 ▒▒RPP*.MNN-.V▒RHK▒)N▒▒▒▒▒&秤▒ģ▒B@▒▒▒▒▒̼t▒̼▒▒ݢ▒▒▒▒T%▒d,W-▒)▒▒K 

如果您使用相同的请求使用纯curl ... -X POST https://www.google.com/recaptcha/api/siteverif bash命令,我会收到正确的数据:

{
  "success": false
}

为什么会发生?

2 个答案:

答案 0 :(得分:3)

nginx配置文件中的

proxy_pass_request_headers off;解决了问题。

location = /recaptcha/api/siteverify {
internal;
resolver   8.8.8.8;
proxy_pass https://www.google.com;
proxy_pass_request_headers off;

}

答案 1 :(得分:0)

我们在第三方扩展中的Magento 1.7.0.2中遇到了同样的问题。仅在特定服务器上获得此类数据

‹       «жRPP*.MNN-.VІR()*MХ  %g$жд¤жҐ§Ж—ЂД•ЊНu
Ќt
CM¬L¬Ќў”А*3т‹KтsSAЄЉJіуSRs2уТхЉJ•ёjЊЗЂ¶^

更改nginx设置没有帮助。原来,这是gzipped答案。 我们已将CURLOPT_ENCODING更改为deflate,问题已解决。