Solved

RestService post Json data

Posted on 2013-01-23
2
412 Views
Last Modified: 2013-01-25
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
0
Comment
Question by:JoeBo747
2 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 38812226
0
 
LVL 1

Author Closing Comment

by:JoeBo747
ID: 38819610
Help me get to the bottom of the problem.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now