# 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
~~~
- README
- 指南
- 概述
- GET Request
- WebRequest
- 属性
- Resource
- Method
- Body
- Format
- RequestFormat
- ResponseFormat
- CustomRequestFormat
- CustomResponseFormat
- ContentType
- Accept
- ContentLength
- FormattedResource
- Cookies
- Headers
- QuerystringParams
- UrlSegments
- 方法
- AddHeader
- SetHeader
- AddUrlSegment
- AddQuerystringParam
- AddCookie
- AddBodyParameter
- CreateFromOptions
- WebClient
- 属性
- BaseUrl
- Authenticator
- TimeoutMs
- ProxyServer
- ProxyBypassList
- ProxyUsername
- ProxyPassword
- EnableAutoProxy
- Insecure
- FollowRedirects
- 方法
- Execute
- GetJson
- PostJson
- SetProxy
- GetFullUrl
- WebResponse
- 属性
- StatusCode
- StatusDescription
- Content
- Data
- Body
- Headers
- Cookies
- 方法
- Update
- WebHelpers
- 属性
- WebStatusCode
- WebMethod
- WebFormat
- UrlEncodingMode
- EnableLogging
- 方法
- LogDebug
- LogWarning
- LogError
- LogRequest
- LogResponse
- Obfuscate
- ParseJson
- ConvertToJson
- ParseUrlEncoded
- ConvertToUrlEncoded
- ParseXml
- ConvertToXml
- ParseByFormat
- ConvertToFormat
- UrlEncode
- UrlDecode
- Base64Encode
- Base64Decode
- RegisterConverter
- JoinUrl
- UrlParts
- CloneDictionary
- CloneCollection
- CreateKeyValue
- FindInKeyValues
- AddOrReplaceInKeyValues
- FormatToMediaType
- MethodToName
- HMACSHA1
- HMACSHA256
- MD5
- CreateNonce
- IWebAuthenticator
- 方法
- BeforeExecute
- AfterExecute
- PrepareHttp
- PrepareCurl
- WebAsyncWrapper
- 属性
- Client
- 方法
- ExecuteAsync
- 范例
- Salesforce网站
- Google APIs
- Todoist API
- 其他主题
- 调试
- 授权
- 实现自己的IWebAuthenticator
- Url编码