16,553
社区成员
发帖
与我相关
我的任务
分享
Private Function DoWebPostRequest(urlPath As String, apiKey As String, postData As String) As String
hr = WebRequest.Create(baseUrl & urlPath)
hr.Method = "POST"
hr.Headers.Add("api-key", apiKey)
hr.GetRequestStream().Write(Encoding.ASCII.GetBytes(postData), 0, postData.Length)
Dim sr As StreamReader = New StreamReader(hr.GetResponse().GetResponseStream)
Return sr.ReadToEnd()
End Function
Private Function GetDeviceInfoByMasterKey(DeviceID As String) As Dictionary(Of String, Object)
Return DoWebGetRequest("/devices/" & DeviceID, txtMasterKey.Text)
End Function
Private Function GetAllDevices() As Dictionary(Of String, Object)
Return DoWebGetRequest("/devices", txtMasterKey.Text)
End Function
Private Function DoWebGetRequest(urlPath As String, apiKey As String)
hr = WebRequest.Create(baseUrl & urlPath)
hr.Method = "GET"
hr.Headers.Add("api-key", apiKey)
Dim sr As StreamReader = New StreamReader(hr.GetResponse().GetResponseStream)
Dim tmp As Dictionary(Of String, Object) = json.DeserializeObject(sr.ReadToEnd())
If tmp("errno") = 0 AndAlso tmp("error") = "succ" Then
Return CType(tmp("data"), Dictionary(Of String, Object))
Else
Return Nothing
End If
End Function