Beispiel #1
0
        private static RestResponse <T> GetRestResponse <T>(string restUri)
            where T : new()
        {
            var ctor = new DefaultUriConstructor("http", "issues.umbraco.org", 80, "");

            var auth = new RestClient();

            auth.RemoveHandler("application/json");

            var req = new RestRequest(ctor.ConstructBaseUri("user/login"), Method.POST);

            req.AddParameter("login", Login);
            req.AddParameter("password", Password);

            var resp   = auth.Execute(req);
            var cookie = resp.Cookies.ToArray();

            var getVBundle = new RestRequest(ctor.ConstructBaseUri(restUri));

            foreach (var restResponseCookie in cookie)
            {
                getVBundle.AddCookie(restResponseCookie.Name, restResponseCookie.Value);
            }

            var gotBundle = auth.Execute <T>(getVBundle);

            return((RestResponse <T>)gotBundle);
        }
Beispiel #2
0
        private RestResponse <T> GetRestResponse <T>(string restUri, bool requestJsonFormat)
            where T : new()
        {
            var ctor = new DefaultUriConstructor("http", "issues.umbraco.org", 80, "");

            var auth = new RestClient();

            auth.RemoveHandler("application/json");

            var req = new RestRequest(ctor.ConstructBaseUri("user/login"), Method.POST);

            req.AddParameter("login", _login);
            req.AddParameter("password", _password);

            var resp = auth.Execute(req);

            if (resp.StatusCode == HttpStatusCode.Forbidden)
            {
                throw new Exception(resp.Content);
            }

            var cookie = resp.Cookies.ToArray();

            var getVBundle = new RestRequest(ctor.ConstructBaseUri(restUri));

            foreach (var restResponseCookie in cookie)
            {
                getVBundle.AddCookie(restResponseCookie.Name, restResponseCookie.Value);
            }

            if (requestJsonFormat)
            {
                getVBundle.AddHeader("Accept", "application/json");
            }

            var gotBundle = auth.Execute <T>(getVBundle);

            return((RestResponse <T>)gotBundle);
        }