0
我想改變請求內容,也就是我想把中文繁體轉換成中文簡體,它們是1:1映射。我使用下面的代碼:asp.net request.filter override stream.read
的Global.asax:
protected void Application_BeginRequest(object sender, EventArgs e)
{
Request.Filter = new RequestFilter(Request.Filter);
}
HttpRequest.filter的用法是在這裏:msdn
RequestFilter:
public override int Read(byte[] buffer, int offset, int count)
{
// the length of buffer is 8192, will truncate my request stream
int len = _sink.Read(buffer, offset, count);
if (len == 0)
{
Array.Clear(buffer, 0, count);
return len;
}
System.Text.Encoding curEncoding = HttpContext.Current.Request.ContentEncoding;
string strBuffer = curEncoding.GetString(buffer);
Regex regQuery = new Regex(@"=([^&]+)", RegexOptions.Compiled);
strBuffer = regQuery.Replace(strBuffer, new MatchEvaluator((match) =>
{
string val = HttpContext.Current.Server.UrlDecode(match.Groups[1].ToString());
return "=" + HttpContext.Current.Server.UrlEncode(ChineseConverter.Convert(val,
ChineseConversionDirection.TraditionalToSimplified));
}));
Array.Clear(buffer, 0, count);
byte[] newBuff = curEncoding.GetBytes(strBuffer);
newBuff.CopyTo(buffer, 0);
return len;
}
我覆蓋的方法讀上流類,但第一個參數字節[]緩衝區默認長度爲8192,並將截斷我的內容。
例如:是encodeURI( '中')是 '%E4%B8%AD',可以是僅 '%E4' 在字節末尾[]緩衝
我怎樣才能獲取第一個參數byte []緩衝區中的所有內容,或者任何人都可以告訴我一些提示來獲取它。