Beispiel #1
0
        public JsonResult GetCaptcha()
        {
            string htmlResult;

            using (var wc = new Infra.CookieAwareWebClient(_cookies))
            {
                wc.Headers[HttpRequestHeader.UserAgent] = "Mozilla/4.0 (compatible; Synapse)";
                wc.Headers[HttpRequestHeader.KeepAlive] = "300";
                htmlResult = wc.DownloadString(UrlBaseReceitaFederal + PaginaPrincipal);
            }

            if (htmlResult.Length <= 0)
            {
                return(null);
            }

            var wc2 = new Infra.CookieAwareWebClient(_cookies);

            wc2.Headers[HttpRequestHeader.UserAgent] = "Mozilla/4.0 (compatible; Synapse)";
            wc2.Headers[HttpRequestHeader.KeepAlive] = "300";
            var data = wc2.DownloadData(UrlBaseReceitaFederal + PaginaCaptcha);

            Session["cookies"] = _cookies;

            return(Json("data:image/jpeg;base64," + Convert.ToBase64String(data, 0, data.Length), JsonRequestBehavior.AllowGet));
        }
        //public ActionResult Excluir(int id)
        //{
        //    try
        //    {
        //        ConsultaDal.Excluir(id);
        //        TempData["Mensagem"] = "Consulta EXCLUIDA com sucesso!";
        //        return Json(true, JsonRequestBehavior.AllowGet);
        //    }
        //    catch (Exception)
        //    {
        //        TempData["Mensagem"] = "Certifique-se que tenha excluido todas as multas relacionados a esta Marca. E tente novamente.";
        //        return Json(false, JsonRequestBehavior.AllowGet);
        //    }
        //}

        public JsonResult GetCaptchaDetran()
        {
            var htmlResult = string.Empty;

            using (var wc = new Infra.CookieAwareWebClient(_cookies))
            {
                wc.Headers[HttpRequestHeader.UserAgent] = "Mozilla/4.0 (compatible; Synapse)";
                wc.Headers[HttpRequestHeader.KeepAlive] = "300";
                htmlResult = wc.DownloadString(urlBaseDetran + paginaPrincipalDetran);
            }

            if (htmlResult.Length > 0)
            {
                var wc2 = new Infra.CookieAwareWebClient(_cookies);
                wc2.Headers[HttpRequestHeader.UserAgent] = "Mozilla/4.0 (compatible; Synapse)";
                wc2.Headers[HttpRequestHeader.KeepAlive] = "300";
                byte[] data = wc2.DownloadData(urlBaseDetran + paginaCaptchaDetran);

                Session["cookies"] = _cookies;

                return(Json("data:image/jpeg;base64," + Convert.ToBase64String(data, 0, data.Length), JsonRequestBehavior.AllowGet));
            }

            return(null);
        }
        public JsonResult GetCaptcha()
        {
            var htmlResult = string.Empty;

            using (var wc = new Infra.CookieAwareWebClient(_cookies))
            {
                wc.Headers[HttpRequestHeader.UserAgent] = "Mozilla/4.0 (compatible; Synapse)";
                wc.Headers[HttpRequestHeader.KeepAlive] = "300";
                htmlResult = wc.DownloadString(urlBaseReceitaFederal + paginaPrincipal);
            }

            if (htmlResult.Length > 0)
            {
                var wc2 = new Infra.CookieAwareWebClient(_cookies);
                wc2.Headers[HttpRequestHeader.UserAgent] = "Mozilla/4.0 (compatible; Synapse)";
                wc2.Headers[HttpRequestHeader.KeepAlive] = "300";
                byte[] data = wc2.DownloadData(urlBaseReceitaFederal + paginaCaptcha);

                Session["cookies"] = _cookies;

                return Json("data:image/jpeg;base64," + Convert.ToBase64String(data, 0, data.Length), JsonRequestBehavior.AllowGet);
            }

            return null;
        }