?? 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 + -