lua 之http请求内部请求

16 篇文章 0 订阅
11 篇文章 0 订阅

### 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即可:
![image.png](https://upload-images.jianshu.io/upload_images/19540485-bd50ef95f679f8f3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
### 在读取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 '';   告诉对方不需要压缩返回
```
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值