Фавориот пост json в vb net - PullRequest
0 голосов
/ 09 октября 2019

Я ищу решение проблемы. Это сообщение в виде скручиваемости в качестве ссылки для выяснения данных json на платформе Favoriot.com.

curl -X POST --header 'Content-Type: application/json'
--header 'Accept: application/json'
--header 'apiKey: YOUR API KEY HERE'
-d '{
"device_developer_id": "deviceDefault@FAVORIOT",
"data": { "temperature": "31","humidity": "70"}
}'

Как я уже упоминал выше, при попытке публикации с использованием vb net .. Я добавил исходный код в качестве ссылки.

Imports Newtonsoft.Json
Imports System.Net
Imports System.Text


Public Class Form1
    Private urlToPost As String = ""
    Private apikey_favoriot As String = "YOUR API KEY HERE"

    Public Sub New(ByVal urlToPost As String)
        Me.urlToPost = urlToPost
    End Sub

    Public Function postData(ByVal dictData As Dictionary(Of String, Object)) As Boolean
        Dim webClient As New WebClient()
        Dim resByte As Byte()
        Dim resString As String
        Dim reqString() As Byte

        Try
            webClient.Headers("content-type") = "application/json"
            webClient.Headers.Add("apikey", apikey_favoriot)
            reqString = Encoding.Default.GetBytes(JsonConvert.SerializeObject(dictData, Formatting.Indented))
            resByte = webClient.UploadData(Me.urlToPost, "post", reqString)
            resString = Encoding.Default.GetString(resByte)
            Console.WriteLine(resString)
            webClient.Dispose()
            Return True
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
        Return False
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Form1 As New Form1("http://192.168.254.104:8000")
        Dim dictData As New Dictionary(Of String, Object)
        dictData.Add("device_developer_id", "deviceDefault@FAVORIOT")
        dictData.Add("data", "temperature : 31")
        Form1.postData(dictData)
    End Sub
End Class
...