using System;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
namespace CsharpHttpHelper
{
///
/// Http返回参数类 Copyright:http://www.httphelper.com/
///
public class HttpResult
{
///
/// Http请求返回的Cookie
///
public string Cookie
{
get;
set;
}
///
/// Cookie对象集合
///
public CookieCollection CookieCollection
{
get;
set;
}
///
/// 返回的String类型数据 只有ResultType.String时才返回数据,其它情况为空
///
public string Html
{
get;
set;
}
///
/// 返回的Byte数组 只有ResultType.Byte时才返回数据,其它情况为空
///
public byte[] ResultByte
{
get;
set;
}
///
/// header对象
///
public WebHeaderCollection Header
{
get;
set;
}
///
/// 返回状态说明
///
public string StatusDescription
{
get;
set;
}
///
/// 返回状态码,默认为OK
///
public HttpStatusCode StatusCode
{
get;
set;
}
///
/// 最后访问的URl
///
public string ResponseUri
{
get;
set;
}
///
/// 获取重定向的URl
///
public string RedirectUrl
{
get
{
try
{
if (Header != null && Header.Count > 0 && Header.AllKeys.Any((string k) => k.ToLower().Contains("location")))
{
string text = ((NameValueCollection)Header)["location"].ToString().Trim();
string text2 = text.ToLower();
if (!string.IsNullOrWhiteSpace(text2) && !text2.StartsWith("http://") && !text2.StartsWith("https://"))
{
text = new Uri(new Uri(ResponseUri), text).AbsoluteUri;
}
return text;
}
}
catch
{
}
return string.Empty;
}
}
}
}