Example #1
0
        public CloudPrinters GetPrinters()
        {
            var printers = new CloudPrinters();

            string authCode;

            if (!Authorize(out authCode))
            {
                return(printers);
            }

            try
            {
                var request = (HttpWebRequest)WebRequest.Create("https://www.google.com/cloudprint/search?output=json");
                request.Method = "POST";

                // Setup the web request
                request.ServicePoint.Expect100Continue = false;

                // Add the headers
                request.Headers.Add("X-CloudPrint-Proxy", Source);
                request.Headers.Add("Authorization", "GoogleLogin auth=" + authCode);

                request.ContentType   = "application/x-www-form-urlencoded";
                request.ContentLength = 0;

                var response        = (HttpWebResponse)request.GetResponse();
                var responseContent = new StreamReader(response.GetResponseStream()).ReadToEnd();

                var serializer = new DataContractJsonSerializer(typeof(CloudPrinters));
                var ms         = new MemoryStream(Encoding.Unicode.GetBytes(responseContent));
                printers = serializer.ReadObject(ms) as CloudPrinters;

                Printers = printers.printers;
                return(printers);
            }
            catch (Exception)
            {
                return(printers);
            }
        }
Example #2
0
        public CloudPrinters GetPrinters()
        {
            var printers = new CloudPrinters();

            string authCode;
            if (!Authorize(out authCode))
                return printers;

            try
            {
                var request = (HttpWebRequest)WebRequest.Create("https://www.google.com/cloudprint/search?output=json");
                request.Method = "POST";

                // Setup the web request
                request.ServicePoint.Expect100Continue = false;

                // Add the headers
                request.Headers.Add("X-CloudPrint-Proxy", Source);
                request.Headers.Add("Authorization", "GoogleLogin auth=" + authCode);

                request.ContentType = "application/x-www-form-urlencoded";
                request.ContentLength = 0;

                var response = (HttpWebResponse)request.GetResponse();
                var responseContent = new StreamReader(response.GetResponseStream()).ReadToEnd();

                var serializer = new DataContractJsonSerializer(typeof(CloudPrinters));
                var ms = new MemoryStream(Encoding.Unicode.GetBytes(responseContent));
                printers = serializer.ReadObject(ms) as CloudPrinters;

                Printers = printers.printers;
                return printers;
            }
            catch (Exception)
            {
                return printers;
            }
        }