GateWay断言的写法及测试

1.断言的官网地址:

https://docs.spring.io/spring-cloud-gateway/docs/current/reference/html/#the-after-route-predicate-factory

2.Cookie断言的使用在这里插入图片描述
3.Cookie的写法说明
在这里插入图片描述
4.使用 curl 进行断言的测试
(1)不带Cookie访问

curl http://localhost:9527/payment/get/1

在这里插入图片描述

(2)带上cookie访问

curl http://localhost:9527/payment/get/2 --cookie "username=zzyy"

在这里插入图片描述
在application.yml中的写法:

- Cookie=username, zzyy

5.Header请求头断言的使用说明
在这里插入图片描述
6.使用 curl 对Header断言进行测试
(1)正确的访问

curl http://localhost:9527/payment/get/2 -H "X-Request-Id:123"

(2)错误的访问

curl http://localhost:9527/payment/get/2 -H "X-Request-Id:-1"

在这里插入图片描述

在application.yml中的写法:

- Header=X-Request-Id, \d+

7.Host主机断言的测试

curl http://localhost:9527/payment/get/2 -H "Host: www.atguigu.com"

application.yml中的写法:冒号后面写多个,用逗号隔开,只需要匹配到其中一个即断言匹配为真

- Host=**.atguigu.com,**.anotherhost.org 

8.Query断言的测试
(1)正确的访问

curl http://localhost:9527/payment/get/2?username=33

(2)错误的访问

curl http://localhost:9527/payment/get/2?username=-31

在application.yml中的写法

- Query=username,\d+

最后,附上生成符合规范的时间的工具类

import java.time.ZonedDateTime;

public class T2
{
    public static void main(String[] args)
    {
        ZonedDateTime zonedDateTime=ZonedDateTime.now();
        System.out.println(zonedDateTime);

        // 2020-04-20T09:44:34.558+08:00[Asia/Shanghai]
    }
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值