thanx agentzh in Chinese mailling-list 's answer
base suggest:
https://github.com/openresty/lua-nginx-module/issues/178#issuecomment-48390360
and:
HttpLuaModule - Nginx Community
http://wiki.nginx.org/HttpLuaModule#ngx.location.capture
...
res = ngx.location.capture(
'/foo/bar',
{ method = ngx.HTTP_POST, body = 'hello, world' }
)
Posting to goo.gl from Android - Stack Overflow
http://stackoverflow.com/questions/6052156/posting-to-goo-gl-from-android
...
post.setEntity(new StringEntity("{\"longUrl\": \"http://www.google.com/\"}"));
...
post.setHeader("Content-Type", "application/json");
i fixed all ;-)
append in nginx.conf:
location /googleapis {
internal;
rewrite ^/googleapis(.*) $1 break;
# to disable gzip compression on the backend
proxy_set_header Accept-Encoding '';
proxy_set_header Content-Type 'application/json';
#proxy_set_header contentType 'application/x-www-form-urlencoded';
proxy_pass https://www.googleapis.com;
}
fixed in lua :
SURI = "https://www.googleapis.com/urlshortener/v1/url"
ngx.say("uri\t", URI)
--DATA = "longUrl=" .. URI
--JSON = '{"longUrl"="' .. URI .. '"}'
local cjson = require "cjson"
JSON = cjson.encode({longUrl=URI})
ngx.say("JSON\t", JSON)
-- search for "openresty" in google over https:
local res = ngx.location.capture(
"/googleapis/urlshortener/v1/url",
{ method = ngx.HTTP_POST,
body = JSON }
)
if res.status ~= 200 then
ngx.say("failed to query google: ", res.status, ": ", res.body)
return
end
-- here we just forward the Google search result page intact:
ngx.header["Content-Type"] = "application/json; charset=UTF-8"
ngx.say(res.body)
testing from China inside GFW:
$ curl -d "uri=https://docs.google.com/forms/d/1TBJNar54XKhMu_nRaES5ByPv0078hh0GV0sD5JPCZGU/viewform"
23.239.0.15:10080/=/goo
request_method: POST
args.uri: https://docs.google.com/forms/d/1TBJNar54XKhMu_nRaES5ByPv0078hh0GV0sD5JPCZGU/viewform
uri https://docs.google.com/forms/d/1TBJNar54XKhMu_nRaES5ByPv0078hh0GV0sD5JPCZGU/viewform
JSON {"longUrl":"https:\/\/docs.google.com\/forms\/d\/1TBJNar54XKhMu_nRaES5ByPv0078hh0GV0sD5JPCZGU\/viewform"}
{
"kind": "urlshortener#url",
"id": "http://goo.gl/fiAfLo",
"longUrl": "https://docs.google.com/forms/d/1TBJNar54XKhMu_nRaES5ByPv0078hh0GV0sD5JPCZGU/viewform"
}
that working!
thanx for all!
On Sun, Aug 10, 2014 at 11:09 PM, Zoom.Quiet <zoom...@gmail.com> wrote:
> my goal act same:
> curl https://www.googleapis.com/urlshortener/v1/url \
> -H 'Content-Type: application/json' \
> -d '{"longUrl": "http://www.google.com/"}'
>
> now i try base
> https://github.com/pintsized/lua-resty-http
>
> as lua ...
>
> URI = "https://docs.google.com/forms/d/1TBJNar54XKhMu_nRaES5ByPv0078hh0GV0sD5JPCZGU/viewform"
> DATA = "longUrl=" .. URI
> SURI = "https://www.googleapis.com/urlshortener/v1/url"
>
> -- For simple singleshot requests, use the URI interface.
> local http = require "resty.http"
> local httpc = http.new()
>
> local res, err = httpc:request_uri(SURI, {
> method = "POST",
> body = DATA,
> headers = {
> ["Content-Type"] = "application/json",
> }
> })
>
> if not res then
> ngx.say("failed to request: ", err)
> ngx.log(ngx.INFO, "httpc:err\t", err)
> return
> end
>
> ngx.status = res.status
> ngx.say(res.body)
>
> ...
>
> BUT the google report:
>
> {"error":
> {"errors":[ {"domain":"global"
> ,"reason":"sslRequired"
> ,"message":"SSLis required to perform this operation."}]
> ,"code":403
> ,"message":"SSL is required to perform this operation."}
> }
>
>
> SO, there is simple way for POST JSON through openresty to https service ?
--
人生苦短, Pythonic! 冗余不做,日子甭过!备份不做,十恶不赦!
KM keep growing environment culture which promoting organization be learnning!
俺: http://zoomquiet.io
许: http://creativecommons.org/licenses/by-sa/2.5/cn/