Ejemplo n.º 1
0
        private static string _getJsonByHttpPostRequest(string urlPath, NameValueCollection values, CookieCollection cookie = null)
        {
            //using (var webReq = new WebRequest())
            //{
            //    var response = webClient.UploadValues(urlPath, values);

            //    string _stringResponse = Encoding.UTF8.GetString(response);
            //    return _stringResponse;
            //}

            using (var webClient = new CookieWebClient())
            {
                var response = webClient.UploadValues(urlPath, values);
                //var a = System.Web.HttpContext.Current.Session["cookie"];

                string _stringResponse = Encoding.UTF8.GetString(response);
                return(_stringResponse);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Авторизация
        /// </summary>
        /// <param name="login"></param>
        /// <param name="apiToken"></param>
        /// <returns></returns>
        public static AuthResult Auth(string login, string apiToken, string host)
        {
            Helpers.host = host;
            Helpers.Init(host);
            var _nvc = new NameValueCollection()
            {
                { "USER_LOGIN", login },
                { "USER_HASH", apiToken },
            };

            AuthResult _ar = null;

            using (var webClient = new CookieWebClient())
            {
                var response = webClient.UploadValues(Helpers.Paths[Helpers.PathsTypes.Authorise], _nvc);
                //var a = System.Web.HttpContext.Current.Session["cookie"];

                string _stringResponse = Encoding.UTF8.GetString(response);
                _ar        = serialiser.Deserialize <AuthResult>(_stringResponse);
                _ar.Cookie = webClient.CookieContainer.GetCookies(new Uri(Helpers.Paths[Helpers.PathsTypes.Authorise]));
                return(_ar);
            }
        }