Kong Gateway - 21 基于网关服务的请求转换器(Request Transformer)

Configure a Service in Kong
[root@contoso ~]# curl -i -X POST \
--url http://localhost:8001/services/ \
--data 'name=country' \

--data 'url=http://contoso.com/v1/countries'

HTTP/1.1 201 Created
Date: Thu, 24 May 2018 00:51:42 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "host": "contoso.com", 
    "created_at": 1527094302, 
    "connect_timeout": 60000, 
    "id": "f45e19af-5528-45c9-af4c-96f3030a3af9", 
    "protocol": "http", 
    "name": "country", 
    "read_timeout": 60000, 
    "port": 80, 
    "path": "/v1/countries", 
    "updated_at": 1527094302, 
    "retries": 5, 
    "write_timeout": 60000
}

Add a Route to expose the Service
URL Format http://localhost:8001/services/{name of servie}/routes
[root@contoso ~]# curl -i -X POST \
--url http://localhost:8001/services/country/routes \
--data 'paths[]=/v1/countries'

HTTP/1.1 201 Created
Date: Thu, 24 May 2018 00:52:03 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "created_at": 1527094323, 
    "strip_path": true, 
    "hosts": null, 
    "preserve_host": false, 
    "regex_priority": 0, 
    "updated_at": 1527094323, 
    "paths": [
        "/v1/countries"
    ], 
    "service": {
        "id": "f45e19af-5528-45c9-af4c-96f3030a3af9"
    }, 
    "methods": null, 
    "protocols": [
        "http", 
        "https"
    ], 
    "id": "0f896042-b496-4cc9-b5a5-cc17f4cf9cb7"   // {route_id} = id
}
======================================================================

范例1:

在项目文件/home/myth/www/bookstore/application/api/controller/v1/Country.php中
修改getCountries方法的实现代码如下:

public function getCountries() {
        return json([
            'RequestHeader'=>['h1'=>request()->header('h1'),'h2'=>request()->header('h2')],
            'ResponseHeader'=>['h1'=>response()->getHeader('h1'),'h2'=>response()->getHeader('h2')],
	]);
        // $countries = Db::table('countries')->paginate(10,false,['query'=>request()->param('page')]);
        // return json($countries);
    }
Add multiple headers by passing each header:value pair separately:
URL Format  http://localhost:8001/services/{name of service}/plugins
[root@contoso ~]# curl -i -X POST \
--url http://localhost:8001/services/country/plugins \
--data "name=request-transformer" \
--data "config.add.headers[1]=h1:v1" \
--data "config.add.headers[2]=h2:v1"
HTTP/1.1 201 Created
Date: Thu, 24 May 2018 00:59:15 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "created_at": 1527123554000, 
    "config": {
        "remove": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "add": {
            "querystring": { }, 
            "headers": [
                "h1:v1", 
                "h2:v1"
            ], 
            "body": { }
        }, 
        "append": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "replace": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "rename": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }
    }, 
    "id": "801f07f4-d9b2-4068-9e8c-898864f39424",    //{plugin_id of the service request-transformer}=id
    "enabled": true, 
    "service_id": "f45e19af-5528-45c9-af4c-96f3030a3af9", 
    "name": "request-transformer"
}
Add multiple headers by passing each header:value pair separately:
URL Format  http://localhost:8001/routes/{route_id}/plugins
[root@contoso ~]# curl -i -X POST \
--url http://localhost:8001/routes/0f896042-b496-4cc9-b5a5-cc17f4cf9cb7/plugins \
--data "name=request-transformer" \
--data "config.add.headers[1]=h1:v1" \
--data "config.add.headers[2]=h2:v1"
HTTP/1.1 201 Created
Date: Thu, 24 May 2018 00:59:34 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "created_at": 1527123574000, 
    "config": {
        "remove": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "add": {
            "querystring": { }, 
            "headers": [
                "h1:v1", 
                "h2:v1"
            ], 
            "body": { }
        }, 
        "append": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "replace": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "rename": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }
    }, 
    "id": "6f0ff345-4600-4291-819d-1f291cdf72e7",    //{plugin_id of the route request-transformer}=id
    "enabled": true, 
    "route_id": "0f896042-b496-4cc9-b5a5-cc17f4cf9cb7", 
    "name": "request-transformer"
}
Testing to check if header parameter is valid

[root@contoso ~]# curl -i -X GET http://contoso.org:8000/v1/countries?page=5

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 78
Connection: keep-alive
Date: Thu, 24 May 2018 01:03:39 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.1.13
X-Powered-By: PHP/7.1.13
X-RateLimit-Limit-countries: countries=3
X-Kong-Upstream-Latency: 19
X-Kong-Proxy-Latency: 40
Via: kong/0.13.1

{"RequestHeader":{"h1":"v1","h2":"v1"},"ResponseHeader":{"h1":null,"h2":null}}


======================================================================

范例2:

修改已配置的header键-值对信息,把h2:v1修改为h2:v2
URL Format  http://localhost:8001/plugins/{plugin_id of the service request-transformer}
[root@contoso ~]# curl -i -X PATCH \
--url http://localhost:8001/plugins/801f07f4-d9b2-4068-9e8c-898864f39424 \
--data "config.add.headers=h1:v1,h2:v2"

HTTP/1.1 200 OK
Date: Thu, 24 May 2018 01:46:30 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "created_at": 1527123554000, 
    "config": {
        "remove": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "add": {
            "querystring": { }, 
            "headers": [
                "h1:v1", 
                "h2:v2"
            ], 
            "body": { }
        }, 
        "append": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "replace": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "rename": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }
    }, 
    "id": "801f07f4-d9b2-4068-9e8c-898864f39424",    //{plugin_id of the service request-transformer}=id
    "enabled": true, 
    "service_id": "f45e19af-5528-45c9-af4c-96f3030a3af9", 
    "name": "request-transformer"
}
修改已配置的header键-值对信息,把h2:v1修改为h2:v2
URL Format  http://localhost:8001/plugins/{plugin_id of the route request-transformer}
[root@contoso ~]# curl -i -X PATCH \
--url http://localhost:8001/plugins/6f0ff345-4600-4291-819d-1f291cdf72e7 \
--data "config.add.headers=h1:v1,h2:v2"
HTTP/1.1 200 OK
Date: Thu, 24 May 2018 01:46:54 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "created_at": 1527123574000, 
    "config": {
        "remove": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "add": {
            "querystring": { }, 
            "headers": [
                "h1:v1", 
                "h2:v2"
            ], 
            "body": { }
        }, 
        "append": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "replace": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "rename": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }
    }, 
    "id": "6f0ff345-4600-4291-819d-1f291cdf72e7",   //{plugin_id of the route request-transformer}=id
    "enabled": true, 
    "route_id": "0f896042-b496-4cc9-b5a5-cc17f4cf9cb7", 
    "name": "request-transformer"
}
Testing to check if header parameter is valid
[root@contoso ~]# curl -i -X GET http://contoso.org:8000/v1/countries?page=5
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 78
Connection: keep-alive
Date: Thu, 24 May 2018 01:49:17 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.1.13
X-Powered-By: PHP/7.1.13
X-RateLimit-Limit-countries: countries=3
X-Kong-Upstream-Latency: 18
X-Kong-Proxy-Latency: 14
Via: kong/0.13.1

{"RequestHeader":{"h1":"v1","h2":"v2"},"ResponseHeader":{"h1":null,"h2":null}}

1.根据{name of service}获取{plugin_id of the service request-transformer}
[root@contoso ~]# curl -i -X GET http://localhost:8001/services/country/plugins    
2.根据{route_id}获取{plugin_id of the route request-transformer}
[root@contoso ~]# curl -i -X GET http://localhost:8001/routes/0f896042-b496-4cc9-b5a5-cc17f4cf9cb7/plugins  
3.根据{plugin_id of the service request-transformer}删除the service request-transformer插件配置数据
[root@contoso ~]# curl -i -X DELETE \
--url http://localhost:8001/plugins/801f07f4-d9b2-4068-9e8c-898864f39424    
4.根据{plugin_id of the route request-transformer}删除the route request-transformer插件配置数据
[root@contoso ~]# curl -i -X DELETE \
--url http://localhost:8001/plugins/6f0ff345-4600-4291-819d-1f291cdf72e7    

5.Add multiple headers by passing comma separated header:value pair:
curl -i -X POST http://localhost:8001/services/country/plugins \
--data "name=request-transformer" \
--data "config.add.headers=h1:v1,h2:v2"

6.Add multiple headers by passing comma separated header:value pair:
curl -i -X POST \
--url http://localhost:8001/routes/0f896042-b496-4cc9-b5a5-cc17f4cf9cb7/plugins \
--data "name=request-transformer" \
--data "config.add.headers=h1:v1,h2:v2"
以上6条命令等价于本范例2条PATCH命令,Kong终端命令的更新令只支持PATCH方法不支持PUT方法,
有关这6条命令详细的执行过程省略跳过.

======================================================================

范例3:

1.根据{name of service}获取{plugin_id of the service request-transformer}
[root@contoso ~]# curl -i -X GET http://localhost:8001/services/country/plugins    
2.根据{route_id}获取{plugin_id of the route request-transformer}
[root@contoso ~]# curl -i -X GET http://localhost:8001/routes/0f896042-b496-4cc9-b5a5-cc17f4cf9cb7/plugins  
3.根据{plugin_id of the service request-transformer}删除the service request-transformer插件配置数据
[root@contoso ~]# curl -i -X DELETE \
--url http://localhost:8001/plugins/801f07f4-d9b2-4068-9e8c-898864f39424    
4.根据{plugin_id of the route request-transformer}删除the route request-transformer插件配置数据
[root@contoso ~]# curl -i -X DELETE \
--url http://localhost:8001/plugins/6f0ff345-4600-4291-819d-1f291cdf72e7

5.Add multiple headers passing config as JSON body:
[root@contoso ~]# curl -i -X POST \
--url http://localhost:8001/services/country/plugins \
--header 'content-type: application/json' \
--data '{"name": "request-transformer", "config": {"add": {"headers": ["h1:v2", "h2:v1"]}}}'

HTTP/1.1 201 Created
Date: Thu, 24 May 2018 02:42:41 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "created_at": 1527129761000, 
    "config": {
        "remove": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "add": {
            "querystring": { }, 
            "headers": [
                "h1:v2", 
                "h2:v1"
            ], 
            "body": { }
        }, 
        "append": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "replace": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "rename": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }
    }, 
    "id": "d2de9bac-b0cf-4838-b477-fa2e8ec6a000",    //{plugin_id of the service request-transformer}=id
    "enabled": true, 
    "service_id": "f45e19af-5528-45c9-af4c-96f3030a3af9", 
    "name": "request-transformer"
}
6.Add multiple headers passing config as JSON body:
[root@contoso ~]# curl -i -X POST \
--url http://localhost:8001/routes/0f896042-b496-4cc9-b5a5-cc17f4cf9cb7/plugins \
--header 'content-type: application/json' \
--data '{"name": "request-transformer", "config": {"add": {"headers": ["h1:v2", "h2:v1"]}}}'
HTTP/1.1 201 Created
Date: Thu, 24 May 2018 02:43:01 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "created_at": 1527129781000, 
    "config": {
        "remove": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "add": {
            "querystring": { }, 
            "headers": [
                "h1:v2", 
                "h2:v1"
            ], 
            "body": { }
        }, 
        "append": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "replace": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "rename": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }
    }, 
    "id": "79d782d0-979b-4246-bf02-cec176e209f6",    //{plugin_id of the route request-transformer}=id
    "enabled": true, 
    "route_id": "0f896042-b496-4cc9-b5a5-cc17f4cf9cb7", 
    "name": "request-transformer"
}
Testing to check if header parameter is valid
[root@contoso ~]# curl -i -X GET http://contoso.org:8000/v1/countries?page=5
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 78
Connection: keep-alive
Date: Thu, 24 May 2018 02:48:51 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.1.13
X-Powered-By: PHP/7.1.13
X-RateLimit-Limit-countries: countries=3
X-Kong-Upstream-Latency: 21
X-Kong-Proxy-Latency: 2
Via: kong/0.13.1

{"RequestHeader":{"h1":"v2","h2":"v1"},"ResponseHeader":{"h1":null,"h2":null}}


======================================================================

范例4:

在项目文件/home/myth/www/bookstore/application/api/controller/v1/Country.php中
修改getCountries方法的实现代码如下:

public function getCountries() {
        return json([
            'RequestHeader'=>[
                'h1'=>request()->header('h1'),'h2'=>request()->header('h2'),
                'q1'=>request()->param('q1'),'q2'=>request()->param('q2'),
             ],
            'ResponseHeader'=>['h1'=>response()->getHeader('h1'),'h2'=>response()->getHeader('h2')],
	]);
        // $countries = Db::table('countries')->paginate(10,false,['query'=>request()->param('page')]);
        // return json($countries);
    }
1.根据{name of service}获取{plugin_id of the service request-transformer}
[root@contoso ~]# curl -i -X GET http://localhost:8001/services/country/plugins    
2.根据{route_id}获取{plugin_id of the route request-transformer}
[root@contoso ~]# curl -i -X GET http://localhost:8001/routes/0f896042-b496-4cc9-b5a5-cc17f4cf9cb7/plugins  
3.根据{plugin_id of the service request-transformer}删除the service request-transformer插件配置数据
[root@contoso ~]# curl -i -X DELETE \
--url http://localhost:8001/plugins/d2de9bac-b0cf-4838-b477-fa2e8ec6a000    
4.根据{plugin_id of the route request-transformer}删除the route request-transformer插件配置数据
[root@contoso ~]# curl -i -X DELETE \
--url http://localhost:8001/plugins/79d782d0-979b-4246-bf02-cec176e209f6


5.Add a querystring and a header:
[root@contoso ~]# curl -i -X POST \
--url http://localhost:8001/services/country/plugins \
--data "name=request-transformer" \
--data "config.add.querystring=q1:v2,q2:v1" \
--data "config.add.headers=h1:v1"

HTTP/1.1 201 Created
Date: Thu, 24 May 2018 03:01:44 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "created_at": 1527130903000, 
    "config": {
        "remove": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "add": {
            "querystring": [
                "q1:v2", 
                "q2:v1"
            ], 
            "headers": [
                "h1:v1"
            ], 
            "body": { }
        }, 
        "append": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "replace": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "rename": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }
    }, 
    "id": "481e28dc-4bad-41f3-8a4c-1f210c4a7df6",    //{plugin_id of the service request-transformer}=id
    "enabled": true, 
    "service_id": "f45e19af-5528-45c9-af4c-96f3030a3af9", 
    "name": "request-transformer"
}
6.Add a querystring and a header:
[root@contoso ~]# curl -i -X POST \
--url http://localhost:8001/routes/0f896042-b496-4cc9-b5a5-cc17f4cf9cb7/plugins \
--data "name=request-transformer" \
--data "config.add.querystring=q1:v2,q2:v1" \
--data "config.add.headers=h1:v1"
HTTP/1.1 201 Created
Date: Thu, 24 May 2018 03:02:05 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "created_at": 1527130926000, 
    "config": {
        "remove": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "add": {
            "querystring": [
                "q1:v2", 
                "q2:v1"
            ], 
            "headers": [
                "h1:v1"
            ], 
            "body": { }
        }, 
        "append": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "replace": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }, 
        "rename": {
            "querystring": { }, 
            "headers": { }, 
            "body": { }
        }
    }, 
    "id": "fbf9b2f2-751e-4544-8c94-8447ea1d2807",    //{plugin_id of the route request-transformer}=id
    "enabled": true, 
    "route_id": "0f896042-b496-4cc9-b5a5-cc17f4cf9cb7", 
    "name": "request-transformer"
}
1).Testing to check if header parameter and query parameter is valid
[root@contoso ~]# curl -i -X GET http://contoso.org:8000/v1/countries?page=5
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 98
Connection: keep-alive
Date: Thu, 24 May 2018 03:22:20 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.1.13
X-Powered-By: PHP/7.1.13
X-RateLimit-Limit-countries: countries=3
X-Kong-Upstream-Latency: 18
X-Kong-Proxy-Latency: 0
Via: kong/0.13.1

{"RequestHeader":{"h1":"v1","h2":null,"q1":"v2","q2":"v1"},"ResponseHeader":{"h1":null,"h2":null}}
2).Testing to check if header parameter and query parameter is valid
[root@contoso ~]# curl -i -X GET http://contoso.org:8000/v1/countries?page=5&q1=v1
[1] 66970
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 98
Connection: keep-alive
Date: Thu, 24 May 2018 03:15:44 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.1.13
X-Powered-By: PHP/7.1.13
X-RateLimit-Limit-countries: countries=3
X-Kong-Upstream-Latency: 21
X-Kong-Proxy-Latency: 2
Via: kong/0.13.1

{"RequestHeader":{"h1":"v1","h2":null,"q1":"v2","q2":"v1"},"ResponseHeader":{"h1":null,"h2":null}}  // Enter to continue
[1]+  Done                    curl -i -X GET http://contoso.org:8000/v1/countries?page=5
3).Testing to check if header parameter and query parameter is valid
[root@contoso ~]# curl -i -X GET http://contoso.org:8000/v1/countries?page=5&q1=v2
[1] 67502
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 98
Connection: keep-alive
Date: Thu, 24 May 2018 03:17:41 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.1.13
X-Powered-By: PHP/7.1.13
X-RateLimit-Limit-countries: countries=3
X-Kong-Upstream-Latency: 16
X-Kong-Proxy-Latency: 34
Via: kong/0.13.1

{"RequestHeader":{"h1":"v1","h2":null,"q1":"v2","q2":"v1"},"ResponseHeader":{"h1":null,"h2":null}}  // Enter to continue
[1]+  Done                    curl -i -X GET http://contoso.org:8000/v1/countries?page=5
4).Testing to check if header parameter and query parameter is valid
[root@contoso ~]# curl -i -X GET http://contoso.org:8000/v1/countries?page=5&q1=1024
[1] 68329
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 98
Connection: keep-alive
Date: Thu, 24 May 2018 03:20:51 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.1.13
X-Powered-By: PHP/7.1.13
X-RateLimit-Limit-countries: countries=3
X-Kong-Upstream-Latency: 19
X-Kong-Proxy-Latency: 3
Via: kong/0.13.1

{"RequestHeader":{"h1":"v1","h2":null,"q1":"v2","q2":"v1"},"ResponseHeader":{"h1":null,"h2":null}}  // Enter to continue
[1]+  Done                    curl -i -X GET http://contoso.org:8000/v1/countries?page=5
5).Testing to check if header parameter and query parameter is valid
[root@contoso ~]# curl -i -X GET http://contoso.org:8000/v1/countries?page=5&q1=v2&q2=v1
[1] 69720
[2] 69721
[root@contoso ~]# HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 98
Connection: keep-alive
Date: Thu, 24 May 2018 03:25:54 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.1.13
X-Powered-By: PHP/7.1.13
X-RateLimit-Limit-countries: countries=3
X-Kong-Upstream-Latency: 16
X-Kong-Proxy-Latency: 0
Via: kong/0.13.1

{"RequestHeader":{"h1":"v1","h2":null,"q1":"v2","q2":"v1"},"ResponseHeader":{"h1":null,"h2":null}}  // Enter to continue
[1]-  Done                    curl -i -X GET http://contoso.org:8000/v1/countries?page=5
[2]+  Done                    q1=v2
以上5个测试结果表明header键-值对h1:v1以及用户访问的链接地址不管你是否带上参数q1和q2,
两个查询键-值对q1:v2和q2:v1会固定不变的传输到PHP Restful api 接口,也就是说查询参数q1和q2的值无法再修改啦






======================================================================

范例5:

因为和范例4一样 莫名其妙错误 请大家关注我在官网论坛上的提问吧  看看老外是怎么回答的

https://discuss.konghq.com/t/request-transformer-why-the-curl-terminal-command-output-results-are-different-from-firefox/1186

相关文章
相关标签/搜索
每日一句
    每一个你不满意的现在,都有一个你没有努力的曾经。