I'm working on a C# application that connects to the Appcelerator Cloud Service, so far I can make queries and login, but when I tried to update a Custom Object
I got the following error: The remote server returned an error: (401) Unauthorized
. This is my code for my POST request:
url = "https://api.cloud.appcelerator.com/v1/objects/Reservacion/update.json?key=appkey&id=" + idReservacion + "&noDisponibles=" + noDisponibles;
wrGetUrl = (HttpWebRequest)WebRequest.Create(url);
wrGetUrl.Method = "POST";
wrGetUrl.ContentType = "application/json";
objStream = wrGetUrl.GetResponse().GetResponseStream(); // this is the line where the error is thrown
reader = new StreamReader(objStream);
I have a theory and it involves the login, at the beginning of my application I make a login which return an ok status, but I think I need to somehow let know ACS I logged in already by sending the session id or something like that when I try to update the Custom Object
.
Edit That is why I tried to add the cookie in the header like this:
url = "https://api.cloud.appcelerator.com/v1/objects/Reservacion/update.json?key=appkey&id=" + idReservacion + "&noDisponibles=" + noDisponibles;
wrGetUrl = (HttpWebRequest)WebRequest.Create(url);
wrGetUrl.Method = "POST";
wrGetUrl.ContentType = "application/json";
wrGetUrl.Headers.Add("Set-Cookie", "_session_id=" + session + "; path=/; HttpOnly");
objStream = wrGetUrl.GetResponse().GetResponseStream(); // this is the line where the error is thrown
reader = new StreamReader(objStream);
Where session
is the session id I got from my successful login. But even though I added this to the headers in my request the error The remote server returned an error: (401) Unauthorized
.
Edit: I tried something else:
url = "https://api.cloud.appcelerator.com/v1/objects/Reservacion/update.json?key=appkey&id=" + idReservacion + "&noDisponibles=" + noDisponibles;
wrGetUrl = (HttpWebRequest)WebRequest.Create(url);
wrGetUrl.Method = "POST";
wrGetUrl.ContentType = "application/json";
wrGetUrl.Headers.Add("Cookie", session); //changed the header but it didn't work
objStream = wrGetUrl.GetResponse().GetResponseStream(); // still throws the same error
reader = new StreamReader(objStream);
How can I solve this problem? Thanks for any help in advance.