HtttpHelper万能框架更新到V1.9.0.2版本,请大家及时更新下载
本新主要更新Bug有
优化自动识别编码功能
部门代码如下
[C#] 纯文本查看 复制代码 /// <summary>
/// 设置编码
/// </summary>
/// <param name="item">HttpItem</param>
/// <param name="result">HttpResult</param>
/// <param name="ResponseByte">byte[]</param>
private void SetEncoding(HttpItem item, HttpResult result, byte[] ResponseByte)
{
//是否返回Byte类型数据
if (item.ResultType == ResultType.Byte) result.ResultByte = ResponseByte;
//从这里开始我们要无视编码了
if (encoding == null)
{
Match meta = Regex.Match(Encoding.Default.GetString(ResponseByte), RegexString.Enconding, RegexOptions.IgnoreCase);
string c = string.Empty;
if (meta != null && meta.Groups.Count > 0)
{
c = meta.Groups[1].Value.ToLower().Trim();
}
string cs = string.Empty;
if (!string.IsNullOrWhiteSpace(response.CharacterSet))
{
cs = response.CharacterSet.Trim().Replace("\"", "").Replace("\'", "");
}
if (c.Length > 2)
{
try
{
encoding = Encoding.GetEncoding(c.Replace("\"", string.Empty).Replace("'", "").Replace(";", "").Replace("iso-8859-1", "gbk").Trim());
}
catch
{
if (string.IsNullOrEmpty(cs))
{
encoding = Encoding.UTF8;
}
else
{
encoding = Encoding.GetEncoding(cs);
}
}
}
else
{
if (string.IsNullOrEmpty(cs))
{
encoding = Encoding.UTF8;
}
else
{
encoding = Encoding.GetEncoding(cs);
}
}
}
}
StringToBase64修改方法名为ByteToBase64
[C#] 纯文本查看 复制代码 /// <summary>
/// 将字节数组为Base64编码
/// </summary>
/// <param name="bytebase">要编码的byte[]</param>
/// <returns>base字符串</returns>
public static string ByteToBase64(byte[] bytebase)
{
return Base64Helper.StringToBase64(bytebase);
}
|