Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guy,

I want use Visual Basic to call restful api.
My api have @RequestBody because i use springboot to build rest and http method: POST.

Please help me call rest api using

Many thank!

What I have tried:

Hi guy,

I want use Visual Basic to call restful api.
My api have @RequestBody because i use springboot to build rest and http method: POST.

Please help me call rest api using 

Many thank!
Posted
Updated 30-Jul-20 19:52pm

Try something like:
VB
Private Async Sub PostMessageTest_Click(sender As Object, e As EventArgs) Handles PostMessageTest.Click
   Dim c As New CustomersRest
   c.FirstName = "Bill"
   c.LastName = "Gates"
   c.CustomerID = Guid.Empty
   Dim RestURL As String = "https://example.com/api/customers/"
   Dim client As New Http.HttpClient
   Dim JsonData As String = JsonConvert.SerializeObject(c)
   Dim RestContent As New Http.StringContent(JsonData, Encoding.UTF8, "application/json")
   Dim RestResponse As Http.HttpResponseMessage = Await client.PostAsync(RestURL, RestContent)
   ResultMessage.Text = RestResponse.StatusCode.ToString
End Sub

Data passed in body is of type "application/json"

Here, for reference:
Setup POST REST Webservice with ASP.net and VB.net - dotnetco.de[^]
How to: Send data by using the WebRequest class | Microsoft Docs[^]
 
Share this answer
 
 
Share this answer
 
Comments
sontn15 29-Jul-20 4:37am    
I search google but i dont have an answer for my question, please send my example :(
Richard MacCutchan 29-Jul-20 5:43am    
The first link in the Google search results explains it in detail.
SezMe 19-Aug-21 9:04am    
Google results are not necessarily the same for everyone. Your first result might even be on a different page for someone else.
Ranchhand61 11-Aug-21 13:50pm    
Always good for the watchmen at the ivory towers of knowledge to chime in. Those that know all, and share none...
Richard MacCutchan 12-Aug-21 3:21am    
Well, you are a year too late, and I do not see your solution anywhere.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900