Appearance
Http
发送一个Http请求
业务属性
属性 | 含义 | 说明 | 输入限定 | 示例值 |
---|---|---|---|---|
enable | 是否启用该控件,未启用时不编译 | 是否编译 | 选择值 | 启用 |
name | 控件返回值命名 | 控件输出值变量名 | 常量 | httpResponse |
text | 与控件关联的文本 | 设计页控件显示 | 常量 | http |
upstream | 上游服务 | 选择值 | upstream1 | |
method | HTTP方法 | Post /GET | 选择值 | GET |
uri | 服务路由 | 未选择上游时请输入绝对路径 | 常量 /流程变量 | #{uri} |
headers | HTTP请求头 | key:常量 value: 常量 /流程变量 | key:h1 value:#{h1} | |
requestBody | HTTP请求体 | 常量,Json/Xml数据节点可用流程变量 /流程变量 | {"a":"#{a}"} | |
original | 原始报文 | 默认返回对象实体 | 选择值 | 禁用 |
throwable | 发生异常时中断请求 | 启用:控件执行异常时立即中断请求,并返回错误 禁用:控件执行异常时将被忽略,并继续执行其后的流程 控件底层使用http应用层传输协议。 当http请求失败或http响应状态码不是 200 (http请求成功状态码)时,代表发生异常 | 选择值 | 启用 |
输出值
- 正常请求输出值
Http控件返回以属性name为名称的实体,该实体包含表示http响应结果的属性result。
当属性original为 “启用” 时,result为http响应原始报文。
当属性original为 “禁用” 时,result为符合Json格式的http响应报文的反序列化实体对象。
注意:当http响应报文不符合Json格式时,result为空的实体对象
- throwable为 “禁用” ,http请求异常时控件输出值
控件返回以属性name为名称的实体,该实体包含表示异常信息的属性err(此时属性result为nil)。
使用示例
假设有一原路返回http请求中的body参数的接口,我们使用Http控件对其发送请求。
实体对象输出
控件返回值命名为 httpResponse
method选择 POST
uri输入 http://localhost:6636/api/return

headers 选择 Content-Type
,application/json

http请求体requestBody 输入:
json
{
"text": "this is a text from body"
}
{
"text": "this is a text from body"
}

original 属性设置为:禁用
使用Return控件对http请求的返回值进行输出:

Return控件的data属性输入:
json
{
"httpResponse": "#{httpResponse}"
}
{
"httpResponse": "#{httpResponse}"
}
使用curl请求接口:
$ curl http://localhost:6636/api/http
$ curl http://localhost:6636/api/http
接口返回:
json
{
"httpResponse": {
"result": {
"text": "this is a text from body"
}
}
}
{
"httpResponse": {
"result": {
"text": "this is a text from body"
}
}
}
原始报文输出
以上示例中,将http控件的original 属性设置为:启用
使用curl请求接口:
$ curl http://localhost:6636/api/http
$ curl http://localhost:6636/api/http
接口返回:
json
{
"httpResponse": {
"result": "{\"text\":\"this is a text from body\"}"
}
}
{
"httpResponse": {
"result": "{\"text\":\"this is a text from body\"}"
}
}
使用变量参数
我们在上述示例的基础上作修改,使用变量替代常量。
首先使用LuaScript控件定义参数
lua
local http_url = "http://localhost:6636/api/return"
local content_type = "application/json"
local request_body = { text = "this is a custom param"}
local http_url = "http://localhost:6636/api/return"
local content_type = "application/json"
local request_body = { text = "this is a custom param"}


修改headers

使用curl请求接口:
$ curl http://localhost:6636/api/http
$ curl http://localhost:6636/api/http
接口返回:
json
{
"httpResponse": {
"result": {
"text": "this is a custom param"
}
}
}
{
"httpResponse": {
"result": {
"text": "this is a custom param"
}
}
}