Internet of Things IoT Frameworks . 1 year ago

Favoriot post json in vb net

Favoriot post json in vb net

0 views   0   0 likes   0 shares Tuteehub forum manpreet 0 answers
_x000D_ _x000D_ I am looking for solution to encounter my problem. This curl post as your reference to figure out post json data to platform. 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"} }' As I mentioned above, trying to post using vb net.. I attached the source code as your reference. 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("") 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
Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.


Tuteehub forum answer Answers (0)

Related Tags

AskAnything Ask Anything

Ask Me Anything

ask me anything tuteehub

Hello! How can I assist you today?
Whether you have questions, need information, or just want to chat, feel free to let me know