old_flsystem/类库/HttpHelper2.1/BaseBll/HttpHelperBll.cs

74 lines
1.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using CsharpHttpHelper.Base;
using CsharpHttpHelper.Enum;
using CsharpHttpHelper.Helper;
using System.Drawing;
namespace CsharpHttpHelper.BaseBll
{
/// <summary>
/// 具体实现方法 Copyrighthttp://www.httphelper.com/
/// </summary>
internal class HttpHelperBll
{
/// <summary>
/// Httphelper原始访问类对象
/// </summary>
private HttphelperBase httpbase = new HttphelperBase();
/// <summary>
/// 根据相传入的数据,得到相应页面数据
/// </summary>
/// <param name="item">参数类对象</param>
/// <returns>返回HttpResult类型</returns>
internal HttpResult GetHtml(HttpItem item)
{
if (item.Allowautoredirect && item.AutoRedirectCookie)
{
HttpResult httpResult = null;
for (int i = 0; i < 100; i++)
{
item.Allowautoredirect = false;
httpResult = httpbase.GetHtml(item);
if (string.IsNullOrWhiteSpace(httpResult.RedirectUrl))
{
break;
}
item.URL = httpResult.RedirectUrl;
item.Method = "GET";
if (item.ResultCookieType == ResultCookieType.String)
{
item.Cookie += httpResult.Cookie;
}
else
{
item.CookieCollection.Add(httpResult.CookieCollection);
}
}
return httpResult;
}
return httpbase.GetHtml(item);
}
/// <summary>
/// 根据Url获取图片
/// </summary>
/// <param name="item">参数类对象</param>
/// <returns>返回图片</returns>
internal Image GetImage(HttpItem item)
{
item.ResultType = ResultType.Byte;
return ImageHelper.ByteToImage(GetHtml(item).ResultByte);
}
/// <summary>
/// 快速Post数据这个访求与GetHtml一样只是不接收返回数据只做提交。
/// </summary>
/// <param name="item">参数类对象</param>
/// <returns>返回HttpResult类型</returns>
internal HttpResult FastRequest(HttpItem item)
{
return httpbase.FastRequest(item);
}
}
}