Google Translator不支持C#和asp.net。 [英] Google Translator is not working with C# and asp.net.

查看:117
本文介绍了Google Translator不支持C#和asp.net。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网络应用程序中使用谷歌翻译器进行英语到印度语翻译。

我得到例外,因为

远程服务器返回错误:( 407)需要代理验证。

我的代码是:



public string Translate(string pText,string pFromCulture,string pToCulture)

{

试试

{

pFromCulture = pFromCulture.ToLower();

pToCulture = pToCulture.ToLower();

string tUrl = string.Format(@http://translate.google.com/translate_a/t?client=j&text={0 }& hl = en& sl = {1}& tl = {2},HttpUtility.UrlEncode(pText),pFromCulture,pToCulture);

string tHtml = null;



WebClient web = new WebClient();

web.Headers.Add(HttpRequestHeader.UserAgent,Mozilla / 5.0);

web.Heade rs.Add(HttpRequestHeader.AcceptCharset,UTF-8);

web.Encoding = Encoding.UTF8;

tHtml = web.DownloadString(tUrl);



string tResult = Regex.Match(tHtml,trans\:( \。*?\),\,RegexOptions.IgnoreCase) .Groups [1] .Value;

JavaScriptSerializer tJSer = new JavaScriptSerializer();

//返回tJSer.Deserialize(tResult,typeof(string));

返回tJSer.Deserialize< string>(tResult).ToString();

}

catch(例外情况)

{

抛出前任;

}



}



i am call fuction as:

翻译(EDUCATION,en,hi);







我急需解决方案。

提前致谢。

i am using google translator in web application for English to Hindi translation.
I am getting exception as
"The remote server returned an error: (407) Proxy Authentication Required."
My code is :

public string Translate(string pText, string pFromCulture, string pToCulture)
{
try
{
pFromCulture = pFromCulture.ToLower();
pToCulture = pToCulture.ToLower();
string tUrl = string.Format(@"http://translate.google.com/translate_a/t?client=j&text={0}&hl=en&sl={1}&tl={2}", HttpUtility.UrlEncode(pText), pFromCulture, pToCulture);
string tHtml = null;

WebClient web = new WebClient();
web.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0");
web.Headers.Add(HttpRequestHeader.AcceptCharset, "UTF-8");
web.Encoding = Encoding.UTF8;
tHtml = web.DownloadString(tUrl);

string tResult = Regex.Match(tHtml, "trans\" : ( \".*?\"),\"", RegexOptions.IgnoreCase).Groups[1].Value;
JavaScriptSerializer tJSer = new JavaScriptSerializer();
// return tJSer.Deserialize(tResult, typeof(string));
return tJSer.Deserialize<string>(tResult).ToString();
}
catch (Exception ex)
{
throw ex;
}

}

i am calling fuction as :
Translate("EDUCATION", "en", "hi");



I need solution on urgent basis.
Thanks in advance.

解决方案

嗯...再次阅读该消息。它告诉你,你正在通过你的终端上的代理服务器,并且propxy要求你在它让你的HTTP请求到达目的地之前对它进行身份验证。



WebClient类代理 [ ^ ]
Ummm...Read the message again. It's telling you that you're going through a proxy server on your end and that propxy requires you to authenticate to it before it will let your HTTP request go to its destination.

WebClient class Proxy[^]


这篇关于Google Translator不支持C#和asp.net。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆