'Install Newtonsoft.json | |
'----------------------- | |
' | |
'PM> Install-Package Newtonsoft.Json -Version 6.0.8 | |
'Sample Usage | |
'------------ | |
'Dim jsonPost As New JsonPost("http://192.168.254.104:8000") | |
'Dim dictData As New Dictionary(Of String, Object) | |
'dictData.Add("test_key", "test_value") | |
'jsonPost.postData(dictData) | |
Imports Newtonsoft.Json | |
Imports System.Net | |
Imports System.Text | |
Public Class JsonPost | |
Private urlToPost As String = "" | |
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" | |
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 | |
End Class |
This comment has been minimized.
This comment has been minimized.
Awesome! Thanks |
This comment has been minimized.
This comment has been minimized.
This example return the body of the response, what can i do if i also want the head of the response? |
This comment has been minimized.
This comment has been minimized.
Thank you so much!!!!!!!! Finally, all samples i found were missing something for the API i am trying, this worked beautiful |
This comment has been minimized.
This comment has been minimized.
I really appreciate this. Thanks |
This comment has been minimized.
This comment has been minimized.
Thank you very much! i was updating my script from python to vb and this help me very well. |
This comment has been minimized.
This comment has been minimized.
Good work dude. THanks a lot |
This comment has been minimized.
This comment has been minimized.
Great work, thanks a lot. Solved a problem for me immediately where I spent hours trying to do a post request with json post data and additional headers. |
This comment has been minimized.
This comment has been minimized.
i encountered a problem to using button to post the json to the website. this curl post can manage to post data to the website. curl -X POST --header 'Content-Type: application/json' However in vb.net is : 'Install Newtonsoft.json 'Sample Usage 'Dim jsonPost As New JsonPost("http://192.168.254.104:8000") ' favoriot part Imports Newtonsoft.Json Public Class Form1
End Class |
This comment has been minimized.
Thanks so much! Keep up the good work.