예제 #1
0
        public override int Read()
        {
            // Read each character, skipping over characters that XML has prohibited

            int nextCharacter;

            do
            {
                // Read a character

                if ((nextCharacter = base.Read()) == EOF)
                {
                    // If the character denotes the end of the file, stop reading

                    break;
                }
            }
            // Skip the character if it's prohibited, and try the next
            while (!XmlSanitizingStream.IsLegalXmlChar(nextCharacter));

            return(nextCharacter);
        }
예제 #2
0
        public override int Peek()
        {
            // Return the next legl XML character without reading it

            int nextCharacter;

            do
            {
                // See what the next character is

                nextCharacter = base.Peek();
            }while
            (
                // If it's prohibited XML, skip over the character in the stream
                // and try the next.

                !XmlSanitizingStream.IsLegalXmlChar(nextCharacter) &&
                (nextCharacter = base.Read()) != EOF
            );

            return(nextCharacter);
        } // method
예제 #3
0
        private void UploadCallback(IAsyncResult ar)
        {
            try
            {
                HttpWebRequest request  = (HttpWebRequest)ar.AsyncState;
                WebResponse    response = request.GetResponse();
                Stream         stream   = response.GetResponseStream();

                string xml = string.Empty;
                using (GZipStream gzip = new GZipStream(stream, CompressionMode.Decompress))

                    using (XmlSanitizingStream sr = new XmlSanitizingStream(gzip))
                    {
                        xml = sr.ReadToEnd();
                    }

                result = ar;
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                throw;
            }
        }
예제 #4
0
 /// <summary>
 /// Get whether an integer represents a legal XML 1.0 character. See the
 /// specification at w3.org for these characters.
 /// </summary>
 public static bool IsLegalXmlChar(int character)
 {
     return(XmlSanitizingStream.IsLegalXmlChar("1.0", character));
 }
예제 #5
0
        private void ShowNewFotoCallback(IAsyncResult ar)
        {
            try
            {
                HttpWebRequest request  = (HttpWebRequest)ar.AsyncState;
                WebResponse    response = request.GetResponse();
                Stream         stream   = response.GetResponseStream();
                //Stream stream = request.GetResponse();

                //Stream stream = request.EndGetRequestStream(ar);

                string xml = string.Empty;
                using (GZipStream gzip = new GZipStream(stream, CompressionMode.Decompress))

                    using (XmlSanitizingStream sr = new XmlSanitizingStream(gzip))
                    {
                        xml = sr.ReadToEnd();

                        int start = xml.IndexOf("__VIEWSTATE\" value=\"", 0) + 20;
                        int end   = xml.IndexOf("\" />", start);
                        Viewstate = xml.Substring(start, (end - start));

                        start           = xml.IndexOf("__EVENTVALIDATION\" value=\"", 0) + 26;
                        end             = xml.IndexOf("\" />", start);
                        Eventvalidation = xml.Substring(start, (end - start));
                    }

                ServicePointManager.Expect100Continue = false;

                Uri requestUri = new Uri(FotoSetUrl);

                if (requestUri.Scheme == "https")
                {
                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

                    ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, err) => true;
                }

                request = (HttpWebRequest)WebRequest.Create(requestUri);

                request.CookieContainer = _Container;
                request.Method          = "POST";
                request.Accept          = "image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, */*";
                request.Headers.Add(HttpRequestHeader.AcceptLanguage, "nl-NL,nl;q=0.8,en-US;q=0.6,en-GB;q=0.4,en;q=0.2");
                request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; WOW64; Trident/7.0)";
                request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
                request.Headers.Add("DNT", "1");
                request.Host      = "servit.mijnknltb.nl";
                request.KeepAlive = true;
                request.Headers.Add(HttpRequestHeader.CacheControl, "no-cache");
                request.ContentType = "multipart/form-data; boundary=" + Boundry;

                StringBuilder sbHeader = new StringBuilder();
                sbHeader.AppendLine(Boundry)
                .AppendLine("Content-Disposition: form-data; name=\"__EVENTTARGET\"")
                .AppendLine()
                .AppendLine("UploadButton");
                sbHeader.AppendLine(Boundry)
                .AppendLine("Content-Disposition: form-data; name=\"__EVENTARGUMENT\"")
                .AppendLine()
                .AppendLine();
                sbHeader.AppendLine(Boundry)
                .AppendLine("Content-Disposition: form-data; name=\"__VIEWSTATE\"")
                .AppendLine()
                .AppendLine(Viewstate);
                sbHeader.AppendLine(Boundry)
                .AppendLine("Content-Disposition: form-data; name=\"__EVENTVALIDATION\"")
                .AppendLine()
                .AppendLine(Eventvalidation);
                sbHeader.AppendLine(Boundry)
                .AppendLine("Content-Disposition: form-data; name=\"LabelCrmControl1$HiddenField\"")
                .AppendLine()
                .AppendLine("Bondsnummer:");
                sbHeader.AppendLine(Boundry)
                .AppendLine("Content-Disposition: form-data; name=\"BondsnummerTextBox$TextBox\"")
                .AppendLine()
                .AppendLine(Bondsnummer);
                sbHeader.AppendLine(Boundry)
                .AppendLine("Content-Disposition: form-data; name=\"LabelCrmControl2$HiddenField\"")
                .AppendLine()
                .AppendLine("Naam:");
                sbHeader.AppendLine(Boundry)
                .AppendLine("Content-Disposition: form-data; name=\"LabelCrmControl4$HiddenField\"")
                .AppendLine()
                .AppendLine("Adres:");
                sbHeader.AppendLine(Boundry)
                .AppendLine("Content-Disposition: form-data; name=\"LabelCrmControl5$HiddenField\"")
                .AppendLine()
                .AppendLine("Woonplaats:");
                sbHeader.AppendLine(Boundry)
                .AppendLine("Content-Disposition: form-data; name=\"LabelCrmControl3$HiddenField\"")
                .AppendLine()
                .AppendLine("Fotobestand:");
                sbHeader.AppendLine(Boundry)
                .AppendLine("Content-Disposition: form-data; name=\"FileUploadControl\"; filename=\"\"")
                .AppendLine("Content-Type: application/octet-stream")
                .AppendLine();

                StringBuilder sbFooter = new StringBuilder();
                sbFooter.AppendLine();

                sbFooter.AppendLine(Boundry)
                .AppendLine("Content-Disposition: form-data; name=\"LabelCrmControlHelpText$HiddenField\"")
                .AppendLine()
                .AppendLine("De getoonde foto zal overeenkomen met de foto op de pas.");
                sbFooter.AppendLine(Boundry + "--");


                byte[] header        = Encoding.UTF8.GetBytes(sbHeader.ToString());
                byte[] footer        = Encoding.UTF8.GetBytes(sbFooter.ToString());
                long   contentLength = header.Length + footer.Length;

                request.ContentLength = contentLength;

                using (var requestStream = request.GetRequestStream())
                {
                    requestStream.Write(header, 0, header.Length);
                    requestStream.Write(footer, 0, footer.Length);
                }

                request.BeginGetRequestStream(UploadCallback, request);
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                throw;
            }
        }