public void Authenticate() { //determine protocol from the auth server String PROTOCOL = AuthServer.StartsWith("http://") ? "http://" : "https://"; String url = AuthServer + "/SensorCloud/devices/" + DeviceId + "/authenticate/"; var request = _requests.url(url) .Param("version", "1") .Param("key", DeviceKey) .Accept("application/xdr") .Get(); // check the response code for success if (request.ResponseCode != HttpStatusCode.OK) { throw new AuthenticationException(request.Text); } // Extract the authentication token and server from the response var ms = new MemoryStream(request.Raw); var xdr = new XdrReader(ms); AuthToken = xdr.ReadString(1000); //a token is generally about 60 chars. Limit the read to at most 1000 chars as a precation so in their is a protocol error we don't try to allocate lots of memory ApiServer = PROTOCOL + xdr.ReadString(255); //max length for a FQDN is 255 chars }