zgg> @http.postForm('https://httpbin.org/post', {
.... name: 'zgg',
.... values: [1, 2, 3],
.... }, {
.... Authorization: 'Bearer HelloWorld',
.... })
{
"args": {},
"data": "",
"files": {},
"form": {
"name": "zgg",
"values": [
"1",
"2",
"3"
]
},
"headers": {
"Accept-Encoding": "gzip",
"Authorization": "Bearer HelloWorld",
"Content-Length": "35",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "Go-http-client/2.0",
"X-Amzn-Trace-Id": "Root=1-62b404ea-7271f822152de246228bd973"
},
"json": null,
"origin": "137.59.101.43",
"url": "https://httpbin.org/post"
}
zgg> @http.postJson('https://httpbin.org/post', {
.... name: 'zgg',
.... values: [1, 2, 3],
.... }, {
.... 'X-My-Header': 'My Value lalala',
.... })
{
"args": {},
"data": "{\"name\":\"zgg\",\"values\":[1,2,3]}",
"files": {},
"form": {},
"headers": {
"Accept-Encoding": "gzip",
"Content-Length": "31",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "Go-http-client/2.0",
"X-Amzn-Trace-Id": "Root=1-62b40554-306f51a40a6b9ee901489c05",
"X-My-Header": "My Value lalala"
},
"json": {
"name": "zgg",
"values": [
1,
2,
3
]
},
"origin": "137.59.101.43",
"url": "https://httpbin.org/post"
}
功能:启动一个web服务器,监听listenAddr地址(格式同go的http.ListenAndServe的第一个参数),并用handleFunc处理每个请求。