Link to home
Start Free TrialLog in
Avatar of JoeBo747
JoeBo747

asked on

RestService post Json data

Hi,

I have succesfully manged to use GET to read data from a restservice and am now attempting to POST data to the same service. I have a class which I am converting to json data but I am unsure of how to attach the data to the webrequest. The code is below can anyone advise me?

The Data:

{"text":"Trial from desktop","userID":"JOE","account":"systems","read":"False","subject":"Test","inout":"in"}

The Code correct credentials used in my app:

Private Sub tiggzipost()
        Dim request As HttpWebRequest
        Dim response As HttpWebResponse = Nothing
        Dim reader As StreamReader
        Dim message As New Message()
        message.text = "Trial from desktop"
        message.userID = "JOE"
        message.account = "systems"
        message.read = "false"
        message.subject = "Test"
        message.inout = "in"
        Dim output As String = JsonConvert.SerializeObject(message)
        Debug.Print(output)
        Try


            request = DirectCast(WebRequest.Create ("https://api.tiggzi.com/rest/1/db/collections/messages"), HttpWebRequest)
            request.Credentials = New NetworkCredential("XXXXX", "XXXXX")
            request.Headers.Add("X-Tiggzi-Database-Id:50b3a60XXXXXXXXXXXX")

            request.Method = "POST"
            request.ContentType = "application/json"

           
            response = DirectCast(request.GetResponse(), HttpWebResponse)


            reader = New StreamReader(response.GetResponseStream())

         
            Debug.Print(reader.ReadToEnd())
        Finally
            If Not response Is Nothing Then response.Close()
        End Try
    End Sub
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland 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
Avatar of JoeBo747
JoeBo747

ASKER

Help me get to the bottom of the problem.