Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I trying send information to server this works well but I need convert it to JSON.
How can I do it please?

What I have tried:

Dim xPoslatUmo As String = ConfigurationManager.AppSettings.Item("UMOPoslat")
               If xPoslatUmo = "Ano" Then
                   Dim request As WebRequest = WebRequest.Create(ConfigurationManager.AppSettings.Item("UMOServer"))
                   request.Method = "POST"
                   Dim postdata As String = "{""GENCELEK"":""SAS_CALLC""},{""GENMSGTEXT"":""info""},{""Volat"":" + xvolat + "},{""Stav"":""" + xstav + "},{""Info"":""" + Left(xinfo, 255) + "}"
                   Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postdata)
                   request.ContentType = "application/x-www-form-urlencoded"
                   request.ContentLength = byteArray.Length
                   Dim dataStream As Stream = request.GetRequestStream()
                   dataStream.Write(byteArray, 0, byteArray.Length)
                   dataStream.Close()
                   Dim response As WebResponse = request.GetResponse()
                   mlog.LogujKontroly(postdata)
                   mlog.LogujKontroly("Poslani UMO " + (CType(response, HttpWebResponse)).StatusDescription)
                   response.Close()
               Else
                   mlog.LogujKontroly("Poslani UMO  - je nastaveno neposilat")
               End If
Posted
Updated 10-Jun-22 9:22am

1 solution

So your postdata is a json string and your are trying to send it with the application/x-www-form-urlencoded media type. Is that correct? This would be like opening an Excel workbook with PowerPoint.

Why not use the content type `application/json` for your request?
 
Share this answer
 

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