- http

范式

- http: { url: [, media:][, post:][, headers:][, async:][, path:] }

您可以通过http标签进行网络请求

属性

属性 类型 是否必须 备注
url expr 发起网络请求的目标地址,可以是http或https开头
media expr x post数据的媒体类型,默认为text/plain,可参考MIME类型
post expr x
headers expr x 头信息 可参考HTTP Headers
async boolean x Default = $false
path path x 返回结果存储路径

用法

get请求

- http: {url: '"http://127.0.0.1/echo"', path: "/resp"}

post请求

- http: {url: '"http://127.0.0.1/echo"', post: '"ping"' path: "/resp"}

定义media的post请求

- put: { path: '/req/param1', value: '1' }
- put: { path: '/req/param2', value: '2' }
- jsonstr: { path: '/postBody', value: '$/req' }
- http: {url: '"http://127.0.0.1/echo"', media: 'application/json'  post: '$/postBody' path: "/resp"}

定义headers的get请求

- put: { path: '/headers/Content_Type', value: '"text/plain"' }
- put: { path: '/headers/Custom_Param', value: '"custom param"' }
- http: {url: '"http://127.0.0.1/echo"', headers: '$/headers' , path: "/resp"}

异步请求

- http: {url: '"http://127.0.0.1/echo"', async: '$true'}