The webservice is returning a list of JSON objects. The JSON object is like this:
"id": "1",
"stanze": 2,
"dotazione": [{
"id": 31,
"nome": "Wi-Fi"
},
{
"id": 23,
"nome": "Garden"
},
{
"id": 3,
"nome": "TV"
}]
The RootObject
is a class, generated online automatically for the JSON object structure.
List<RootObject> allObj = new List<RootObject>();
Finally, I want to deserialize the JSON response into a List of RootObject
(s)
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(allObj.ToString());
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("www.thewebservice.com/api");
I've managed to add the header parameters for the web service request.
request.Method = "POST";
request.MediaType = "application/json";
request.ContentType = "application/vnd.api+json";
1st issue: Don't think the ContentLength is set correctly
request.ContentLength = data.Length;/// ????
request.Accept = "application/vnd.api+json";
These are the parameters for header
request.Headers.Add("X-USER", "myuser");
request.Headers.Add("X-PASS", "myuser2018Net");
request.Headers.Add("X-WHAT", "ALLOGGILIST");
request.Headers.Add("X-ACTION", "GET");
2nd issue How to set a parameter for body?
e.g. parameter name = lingua
, value = EN
I tested the webservice using SOAP. And I put the above parameter in the section below the Media Type.