### 1、内部请求单个(只能请求内部服务)
```bash
ngx.location.capture(uri,{options...});
local res = ngx.location.capture("order",{
method = ngx.HTTP_GET, #设置请求方式为get请求
args = {orderId=1,userId=2}, # get请求参数
body = "orderId=1&userId=2" #post请求参数
});
res返回主要包含
status请求的响应状态
header 响应的所有头信息
body 响应体数据,有可能被异常信息截断(truncated)
truncated 是否被截断
```
### 内部请求不允许外部访问,只需要在location内添加internal即可:

### 在读取post请求参数前,必须先设置
ngx.req.read_body;
### 读取post请求参数的方式为:
ngx.req.get_post_args();
# 2、内部请求并发(只能请求内部服务)
```bash
ngx.location.capture_multi({
{ uri,{options...}},
{ uri,{options...}},
{ uri,{options...}}
..............
});
```
### 在请求时,对方返回的是压缩的数据,可以通过配置:
```bash
proxy_set_header Accept-Encoding ''; 告诉对方不需要压缩返回
```
lua 之http请求内部请求
最新推荐文章于 2024-12-23 16:16:40 发布