📄 google.ashx
字号:
<%@ WebHandler Language="C#" Class="Google" %>
using System;
using System.Web;
using System.Text.RegularExpressions;
using System.Xml;
using System.Text;
//在线翻译的handler
public class Google : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string[] postname = context.Request.Params.AllKeys;//所有请求的参数
StringBuilder topost = new StringBuilder();
for (int i = 0; i < postname.Length; i++)//遍历各参数,构造post字符串
{
topost.AppendFormat("{0}={1}&", postname[i], context.Server.UrlEncode(context.Request.Params[postname[i]]));
}
//获得翻译结果
string result = Thief.Post("http://translate.google.com/translate_t", topost.ToString());
//删除不需要的部分
result = Regex.Match(result, "<div id=result_box dir=ltr>[\\s\\S]*?</div>").Value;
result = result.Substring(27);
result = result.Substring(0, result.Length - 6);
context.Response.Write(result);//输出
}
public bool IsReusable//不重用
{
get
{
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -