在HttpItem类里添加两个函数
[C#] 纯文本查看 复制代码 public string DumpHeader()
{
StringBuilder sb = new StringBuilder();
Type type = ((object)this).GetType();
PropertyInfo[] proInfos = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo pi in proInfos)
{
if (pi.GetValue(this, null) != null)
{
if (!string.IsNullOrEmpty(pi.Name) && !string.IsNullOrEmpty(pi.GetValue(this, null).ToString().Trim()))
{
if (pi.PropertyType.Name == "WebHeaderCollection")
{
if (((NameValueCollection)pi.GetValue(this, null)).AllKeys.Length != 0)
{
string value = DumpColl((NameValueCollection)pi.GetValue(this, null));
sb.AppendFormat("{0}={1};\r\n", pi.Name, value);
}
}
else
{
if (pi.PropertyType.Name == "String")
{
sb.AppendFormat("{0}=\"{1}\";\r\n", pi.Name, pi.GetValue(this, null));
}
else
{
sb.AppendFormat("{0}={1};\r\n", pi.Name, pi.GetValue(this, null));
}
}
}
}
}
return sb.ToString();
}
protected string DumpColl(NameValueCollection coll)
{
StringBuilder sb = new StringBuilder();
if (coll != null)
{
int loop1, loop2;
if (coll.AllKeys.Length != 0)
{
try
{
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
sb.AppendFormat(arr1[loop1] + "=");
String[] arr2 = coll.GetValues(arr1[loop1]);
for (loop2 = 0; loop2 < arr2.Length; loop2++)
{
sb.AppendFormat(arr2[loop2] + ";");
}
sb.AppendFormat("\r\n");
}
}
catch
{
}
}
}
return sb.ToString();
}
这是提取发送头的日志。返回头的日志。大家自己加另一个类里 吧
|