WebService: lettura di dati da un servizio WebApi REST con parametri nella request body

  ' In questo esempio viene effettuata la chiamata ad un servizio WebApi REST (webMethod) che restituisce informazioni in formato Json. 
' I parametri anzichè essere accodati alla URL sono inseriti nella request body assemblati in formato JSON

Dim jsonr as string
dim webRequest__1 As Net.HttpWebRequest
dim resp As Net.HttpWebResponse 
dim ok as boolean
dim responseStream as System.io.Stream 
dim sr as System.io.StreamReader
Dim httpResponse As net.HttpWebResponse
dim errCode as string
Dim obj As Newtonsoft.Json.linq.JObject
Dim url As String = "<mettere qui la URL del servizio>" 
webRequest__1 = DirectCast(Net.WebRequest.Create(url), Net.HttpWebRequest)
webRequest__1.Method = "POST"
webRequest__1.ContentType = "application/json"
webRequest__1.Accept = "application/json"
				
jsonr = "{"
jsonr += """contact"": {"
jsonr += """email"": """+q.rowset.fields("EMAIL").value+""","
jsonr += """lastName"": """+q.rowset.fields("DESCPER").value+""","
jsonr += """firstName"": """","
jsonr += """phone"": """+q.rowset.fields("TELEFONO").value+""""
jsonr += "}"
jsonr += "}"
						
webRequest__1.ContentLength = jsonr.ToString().Length

Using requestWriter2 As New IO.StreamWriter(webRequest__1.GetRequestStream())
  requestWriter2.Write(jsonr)
End Using
						
resp = DirectCast(webRequest__1.GetResponse(), Net.HttpWebResponse)

if resp.StatusCode = 200 or resp.StatusCode = 201 then
   responseStream = resp.GetResponseStream()
   sr= new System.IO.StreamReader(responseStream)
   jsonr = sr.ReadToEnd() ' This reads the JSon with the result
							
   obj=Newtonsoft.Json.linq.JObject.Parse(jsonr)	

   ' Questo è un esempio di come recuperare i dati dal JSON di risposta
   id=ctype(obj("contact")("id"),Newtonsoft.Json.Linq.JValue).Value  							
End If