http

http库提供了各种常用的http功能,包括:服务端、客户端、websocket

作为客户端时:

作为服务端时:

函数文档

func get(url, headers?)

用GET方法请求指定url的资源,返回一个Bytes值

若请求失败时,抛出异常

func getJson(url, headers?)

用GET方法请求指定url的资源,并将返回内容按json格式解析为一个ZGG的值

若请求失败时,抛出异常

func postForm(url, form, headers?)

以x-www-form-urlencoded方式往指定URL发起一次Post Form请求。若请求失败则抛出异常。

Examples

func postJson(url, jsonValue, headers?)

往指定URL发起一次Post Json请求。若请求失败则抛出异常。

Examples

type Request

func serve(listenAddr, handleFunc)

功能:启动一个web服务器,监听listenAddr地址(格式同go的http.ListenAndServe的第一个参数),并用handleFunc处理每个请求。

serve函数是一个非常简便的提供http服务的方法,适用于对外提供简单服务。

最后更新于