Hi Lirio,
First you need to POST to rest_access in order to get a session ID
e.g.
HttpWebRequest request = WebRequest.Create("http://localhost:8050/caisd-rest/rest_access") as HttpWebRequest;
request.Method = "POST";
request.Headers.Add("Authorization", "Basic U2VydmljZURlc2s6U0FkMjAyMSM=");
request.ContentType = "application/json";
request.CookieContainer = new CookieContainer();
request.Accept = "application/json";
String body = "{\"rest_access\":{}}";
using (StreamWriter streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(body); }
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
using (var streamreader = new StreamReader(response.GetResponseStream())) {
Console.WriteLine(streamreader.ReadToEnd());
}}
This returns a JSON string such as:
{"rest_access":{"@id":401654,"@REL_ATTR":401654,"@COMMON_NAME":321054765,"link":{"@href":"http://localhost:8050/caisd-rest/rest_access/401654","@rel":"self"},"access_key":321054765,"expiration_date":1689661629}}
The session key is "access_key":321054765 and needs to be passed to subsequent calls as X-Obj-Attrs within the header
e.g.
request = WebRequest.Create("http://localhost:8050/caisd-rest/cnt") as HttpWebRequest;
request.Method = "GET";
request.Headers.Add("X-AccessKey", "321054765");
request.ContentType = "application/json";
request.CookieContainer = new CookieContainer();
request.Accept = "application/json";
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
using (var streamreader = new StreamReader(response.GetResponseStream())) {
Console.WriteLine(streamreader.ReadToEnd());
}}
Regards
Joe