1读恃、內(nèi)部請(qǐng)求單個(gè)(只能請(qǐng)求內(nèi)部服務(wù))
ngx.location.capture(uri,{options...});
local res = ngx.location.capture("order",{
method = ngx.HTTP_GET, #設(shè)置請(qǐng)求方式為get請(qǐng)求
args = {orderId=1,userId=2}, # get請(qǐng)求參數(shù)
body = "orderId=1&userId=2" #post請(qǐng)求參數(shù)
})颗味;
res返回主要包含
status請(qǐng)求的響應(yīng)狀態(tài)
header 響應(yīng)的所有頭信息
body 響應(yīng)體數(shù)據(jù)直奋,有可能被異常信息截?cái)啵╰runcated)
truncated 是否被截?cái)?
內(nèi)部請(qǐng)求不允許外部訪問(wèn)诗越,只需要在location內(nèi)添加internal即可:
在讀取post請(qǐng)求參數(shù)前厘熟,必須先設(shè)置
ngx.req.read_body;
讀取post請(qǐng)求參數(shù)的方式為:
ngx.req.get_post_args();
2匹厘、內(nèi)部請(qǐng)求并發(fā)(只能請(qǐng)求內(nèi)部服務(wù))
ngx.location.capture_multi({
{ uri,{options...}},
{ uri,{options...}},
{ uri,{options...}}
..............
});
在請(qǐng)求時(shí)嘀趟,對(duì)方返回的是壓縮的數(shù)據(jù),可以通過(guò)配置:
proxy_set_header Accept-Encoding ''; 告訴對(duì)方不需要壓縮返回