kong API gateway(二):添加API
来源:互联网 发布:openwrt 挂载网络磁盘 编辑:程序博客网 时间:2024/06/09 21:18
# 可直接通过dashboard添加 --- http://localhost:8080/#/apis/add# 也可以通过Linux curl命令添加参数: 官方参数说明:https://getkong.org/docs/0.11.x/admin-api/#add-api name // 必填 API名称 hosts // 半可选 指向的域名,多个逗号分割 uris // 半可选 逗号分隔的URI列表 methods // 半可选 指向的HTTP方法的,多个逗号分隔 至少有一个'hosts','uris' upstream_url // 必填 代理请求地址,https://www.baidu.com retries // 可选填 代理失败重试次数 默认5 upstream_connect_timeout // 服务连接超时时间 默认60000ms upstream_send_timeout // 连续写入超时时间 默认60000ms upstream_read_timeout // 连续请求超时时间 默认60000ms --- curl -i -X POST \ --url http://localhost:8001/apis/ \ --data 'name=example-api' \ --data 'hosts=example.com' \ --data 'upstream_url=http://httpbin.org'# 官文教程 --- https://getkong.org/docs/0.11.x/getting-started/adding-your-api/# 查看API列表 --- http://localhost:8001/apis http://localhost:8080/#/apis# 查看单个API --- http://localhost:8001/apis/example-api# API转发 --- curl -i -X GET \ --url http://localhost:8000/ \ --header 'Host: example.com'# 注用php的curl模块请求返回来的是no API found with those valueshttps://github.com/postmanlabs/postman-app-support/issues/781(postman)用postman也是no API found with those values用Python的pycurl模块可以访问的添加的API,用request.get返回的no API found with those values用Linux的curl命令完全正常正在找原因,找到在贴出来 --- php code <?php $data = ['Host' => 'example.com']; $url = 'http://localhost:8000/'; function phpcurl($url, $data = []) { // {"message":"no API found with those values"} $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, $data); $res = curl_exec($curl); curl_close($curl); var_export($res); } function sy() { // 可以 $command = "curl -i -X GET --url http://localhost:8000/ --header 'Host: example.com'"; var_export(system( $command)); } //phpcurl($url, $data); //sy(); ----------------------------------------------------------------------------- --- Python code #!/usr/bin/python3 # -*- coding: utf-8 -*- # author=He import pycurl import os import requests headers = {} url = 'http://127.0.0.1:8000' headers['Host'] = 'example.com' # # def header_function(header_line): # headers['Host'] = 'example.com' # # c = pycurl.Curl() # # c.setopt(c.URL, url) # c.setopt(c.HEADERFUNCTION, header_function) # c.perform() # c.close() # command = "curl -i -X GET --url http://localhost:8000/ --header 'Host: example.com'" # r = os.system(command) # print(r) r = requests.get(url, headers) print(r.content.decode())
文章来源:http://blog.csdn.net/qq_26656329/article/details/78293053
阅读全文
0 0
- kong API gateway(二):添加API
- kong API gateway(一):安装
- kong API gateway(三):consumers
- kong API gateway(四):插件
- API GateWay ---Kong 安装注意事项
- kong API gateway(五):upstreams&targets
- kong api gateway 插件之acl
- Kong API Gateway部署手册----安装
- API Gateway
- 云框架发布KONG API Gateway主题,开源求助攻~
- API网关(API Gateway)
- API网关(API Gateway)
- API GATEWAY API 网关
- API网关(API Gateway)
- Improve API Gateway Throttling
- API gateway---orange安装
- 微服务API Gateway
- 使用API Gateway
- 毫秒值与date格式的时间之间的转换
- 国内下载pypi库的方式
- 运行时常用的功能
- 一些被忽略且好用的API
- dex文件格式——思维导图
- kong API gateway(二):添加API
- Matlab 方程组求解
- 进程间通讯-——管道
- 游戏化学习
- Kylin增量cube build的restAPI的时间不准确的BUG
- TCP Connection Establishment Process: The "Three-Way Handshake"
- 小米4A安装App报错INSTALL_FAILED_VERSION_DOWNGRADE
- Java-JDK-Serializable
- Ubuntu下Qt creator无法使用fcitx输入中文之解决办法