C# 谷歌拼写检查器API

C# 谷歌拼写检查器API,c#,asp.net,C#,Asp.net,有人知道吗?我通过了拼写检查“accelerants”,这是一个非常好的单词。我回来“加速”?当我在浏览器中打开Google并键入“accelerants”时,它并不表示“accelerates” 使用系统; Net系统; 使用系统文本; 使用System.Text.RegularExpressions; 命名空间拼写检查 { googel_SP类 { 公共字符串; 公开作废运行() { string retValue=string.Empty; 字符串Iword=“促进剂”; 尝试 { 字符串

有人知道吗?我通过了拼写检查“accelerants”,这是一个非常好的单词。我回来“加速”?当我在浏览器中打开Google并键入“accelerants”时,它并不表示“accelerates”

使用系统;
Net系统;
使用系统文本;
使用System.Text.RegularExpressions;
命名空间拼写检查
{
googel_SP类
{
公共字符串;
公开作废运行()
{
string retValue=string.Empty;
字符串Iword=“促进剂”;
尝试
{
字符串uri=”https://www.google.com/tbproxy/spell?lang=en:";
使用(WebClient WebClient=new WebClient())
{
string postData=string.Format(“”)
+“{0}”,Iword);
webclient.Headers.Add(“内容类型”,“应用程序/x-www-form-urlencoded”);
byte[]bytes=Encoding.ASCII.GetBytes(postData);
byte[]response=webclient.UploadData(uri,“POST”,字节);
字符串数据=Encoding.ASCII.GetString(响应);
if(数据!=string.Empty)
{
retValue=Regex.Replace(数据,@“”,string.Empty).Split('\t')[0];
Console.WriteLine(“word输入->”+word+“word输出->”+retValue);
}
}
}
捕获(异常扩展)
{
}
//返回值;
}
}
}

有趣。。。我运行了你的代码,如果我故意传递“accelerants”作为搜索词,它会正确返回“accelerants”。然而,如果我通过“加速剂”,它会返回“加速”。改变语言和文本编码似乎没有什么不同

下面是做同样工作的替代代码..显然需要一点错误处理,但您得到的想法是:)

using System;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;

namespace SpellCheck
{
    class googel_SP
    {
        public string word;
        public void run_G()
        {
            string retValue = string.Empty;
            string Iword = "accelerants";

            try
            {
                string uri = "https://www.google.com/tbproxy/spell?lang=en:";
                using (WebClient webclient = new WebClient())
                {
                    string postData = string.Format("<?xml version=\"1.0\"     encoding=\"utf-8\" ?> " 
                    + "<spellrequest textalreadyclipped=\"0\" ignoredups=\"0\"     ignoredigits=\"1\" "
                    + "ignoreallcaps=\"1\"><text>{0}</text></spellrequest>", Iword);

                    webclient.Headers.Add("Content-Type", "application/x-www-form-    urlencoded");
                    byte[] bytes = Encoding.ASCII.GetBytes(postData);
                    byte[] response = webclient.UploadData(uri, "POST", bytes);
                    string data = Encoding.ASCII.GetString(response);
                    if (data != string.Empty)
                    {
                        retValue = Regex.Replace(data, @"<(.|\n)*?>",     string.Empty).Split('\t')[0];
                        Console.WriteLine(" word in -> " + word + " word out -> " +      retValue);
                    }
                }
            }
            catch (Exception exp)
            {

            }
            //return retValue;
        }
    }

 }
string retValue = string.Empty;
word = "accelerants";

string uri = string.Format( "http://www.google.com/complete/search?output=toolbar&q={0}", word );

HttpWebRequest request = ( HttpWebRequest ) WebRequest.Create( uri );
HttpWebResponse response = ( HttpWebResponse ) request.GetResponse( );

using ( StreamReader sr = new StreamReader( response.GetResponseStream( ) ) ) {
    retValue = sr.ReadToEnd( );
}

XDocument doc = XDocument.Parse( retValue );

XAttribute attr = doc.Root.Element( "CompleteSuggestion" ).Element( "suggestion" ).Attribute( "data" );

string correctedWord = attr.Value;