Link to home
Start Free TrialLog in
Avatar of Sid Price
Sid PriceFlag for United States of America

asked on

upload JSONobject to web server

I am writing a client application for a networked device. The device requires that control values are changed using html "POST" and sending form data containing a JSON object. The devices has some sample commands using CURL that work fine and I am able to capture the "POSTs" using Wireshark. Here is a capture of a good transaction:

User generated image
I am using VB.NET to write my client application and using WebRequest I can send the value pair but the form data is missing the "json=" part of the data:

User generated image
This is the code I have so far:

        Using sendto As New Net.WebClient
            Dim param As New Specialized.NameValueCollection
            param.Add(theName, theValue)
            Dim response_bytes = sendto.UploadValues(uri, "POST", param)
            Dim response_body = (New Text.UTF8Encoding).GetString(response_bytes)
        End Using

Open in new window


The server rejects the post and closes the connection.

I have searched but cannot find a way to get this data correct. Any pointers would be much appreciated,
Sid.
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,
how do go generate / get
param.Add(theName, theValue)

Open in new window

?

They should look like:
theName = "json"
theValue = "{""value"" : ""1.18""}"
param.Add(theName, theValue)

Open in new window

This should then look identical to your CURL.

HTH
Rainer
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sid Price

ASKER

The answer given by the expert was not a full solution and what I eventually implemented myself resolved the issue.