Example #1
0
        /// <summary>Sends a spell check request to the google speck checking api.</summary>
        /// <param name="request">The google spell check request</param>
        /// <param name="language">The language to spell check with</param>
        /// <param name="encryptRequest">Encrypte request by using https</param>
        /// <returns>An instance of SpellResult containing the corrections</returns>
        public static SpellResult Check(SpellRequest request, CultureInfo language, bool encryptRequest)
        {
            if (request == null)
                throw new ArgumentNullException("request");
            if (language == null)
                throw new ArgumentNullException("language");
            if(Array.BinarySearch(Languages, language.TwoLetterISOLanguageName) < 0)
                throw new ArgumentException("The specified language is not supported.", "language");

            string uriString = BuildUri(language, encryptRequest);

            string requestxml = request.ToString();
            Debug.WriteLine(requestxml);

            byte [] buffer = Encoding.UTF8.GetBytes(requestxml);

            //WebClient webClient = new WebClient();
            //webClient.Headers.Add("Content-Type", "text/xml");

            //byte[] response = webClient.UploadData(uriString, "POST", buffer);

            //string resultXML = Encoding.UTF8.GetString(response);
            //Debug.WriteLine(resultXML);

            HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(uriString);

            httpRequest.Method = "POST";
            httpRequest.ContentType = "text/xml";
            httpRequest.ContentLength = buffer.Length;

            System.IO.Stream postStream = httpRequest.GetRequestStream();
            postStream.Write(buffer, 0, buffer.Length);
            postStream.Close();

            HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();

            System.IO.Stream dataStream = httpResponse.GetResponseStream();

            System.IO.StreamReader streamReader = new System.IO.StreamReader(dataStream);

            String data = streamReader.ReadToEnd();

            streamReader.Close();
            httpResponse.Close();

            SpellResult result = SpellResult.Load(data);

            //SpellResult result = SpellResult.Load(resultXML);

            return result;
        }
Example #2
0
 /// <summary>Sends a spell check request to the google speck checking api.</summary>
 /// <param name="request">The google spell check request</param>
 /// <param name="language">The language to spell check with</param>
 /// <returns>An instance of SpellResult containing the corrections</returns>
 public static SpellResult Check(SpellRequest request, CultureInfo language)
 {
     return SpellCheck.Check(request, language, false);
 }
Example #3
0
 /// <summary>Sends a spell check request to the google speck checking api.</summary>
 /// <param name="request">The google spell check request</param>
 /// <param name="encryptRequest">Encrypte request by using https</param>
 /// <returns>An instance of SpellResult containing the corrections</returns>
 public static SpellResult Check(SpellRequest request, bool encryptRequest)
 {
     return SpellCheck.Check(request, DefaultCulture, encryptRequest);
 }
Example #4
0
 /// <summary>Sends a spell check request to the google speck checking api.</summary>
 /// <param name="request">The google spell check request</param>
 /// <returns>An instance of SpellResult containing the corrections</returns>
 public static SpellResult Check(SpellRequest request)
 {
     return SpellCheck.Check(request, DefaultCulture, false);
 }