🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# GET Request 以下演示了一个简单的GET请求: 1. `Request.Format`设置`RequestFormat`,它设置`Content-Type`头并自动转换请求体,和`ResponseFormat`,它设置`Accept`头并自动转换响应体 2. `Request.Method`使用`WebMethod`枚举来设置请求方法(`GET`,`POST`,`PUT`,`PATCH`和`HEAD`可用) 3. `Client.GetJson`是执行标准`GET` +`json`请求的快捷方式 ~~~ '// (使用概述中的客户端) Public Function GetProject(Id As Long) As Dictionary Dim Request As New WebRequest Request.Resource = "projects/" & Id '// 设置请求和响应格式 '// - 设置Content-Type和Accept标头 '// - 转换请求和响应主体 Request.Format = WebFormat.Json '// 方法: HttpGet = GET '// POST, PUT, DELETE, PATCH, HEAD 也支持 Request.Method = WebMethod.HttpGet Dim Response As WebResponse Set Response = Client.Execute(Request) '// -> GET https://www.example.com/api/projects/1 '// '// <- HTTP/1.1 200 OK '// ... '// {"data":{"id":1,"name":"Project 1"}} If Response.StatusCode = WebStatus.Ok Then '// 基于Request.Format自动解析json响应 Set GetProject = Response.Data("data") End If End Function Public Function GetProject2(Id As Long) As Dictionary '// 对于GET + json,可以使用GetJson '// (相当于上面的GetProject) Dim Response As WebResponse Set Response = Client.GetJson("projects/" & Id) If Response.StatusCode = WebStatus.Ok Then Set GetProject2 = Response.Data("data") End If End Function ~~~