错误的正文内容 ngx.location.capture。

我想使用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
}

这可能是为什么?

点赞
用户1979882
用户1979882

在 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;
}
2015-10-01 15:10:50
用户878257
用户878257

在Magento 1.7.0.2的第三方扩展中出现了相同的问题。只有在特定的服务器上才会得到这样的数据响应:

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

更改nginx设置没有帮助。结果证明这是gzip压缩的响应。我们将CURLOPT_ENCODING更改为deflate,问题得到解决。

2017-12-11 14:47:03