***********************************************************************/
using System;
using MSXML2;
namespace ebcnc
{
/// <summary>
/// XMLHTTP基类
/// </summary>
public class XMLHTTP : IDisposable
{
#region 变量及参数
private XMLHTTPClass xml;
private bool _alreadyDispose = false;
public ST_Param Parameters;
public enum SendMethod : int
{
POST, GET
}
#endregion
#region 参数结构体
public struct ST_Param
{
public string Url;
public string Parameters;
public string Uid;
public string Pwd;
}
#endregion
#region 发送数据
/// <summary>
/// 发送数据
/// </summary>
/// <param name="method">发送方式</param>
/// <param name="p">数据</param>
/// <returns>STRING</returns>
public virtual string SendCommand(SendMethod method, ST_Param p)
{
if (p.Url == null || p.Url == "") return null;
if (method == SendMethod.POST)
{
try
{
xml.open("POST", p.Url, false, p.Uid, p.Pwd);
xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xml.send(CommonFunction.UrlEncoding(p.Parameters));
if (xml.status == 200)
{
return System.Text.Encoding.Default.GetString((byte[])xml.responseBody);
}
else
{
return xml.status.ToString();
}
}
catch (Exception E)
{
return E.Message.ToString();
}
}
else if (method == SendMethod.GET)
{
xml.open("GET", p.Url + "?" + CommonFunction.UrlEncoding(p.Parameters), false, p.Uid, p.Pwd);
xml.send(null);
return System.Text.Encoding.Default.GetString((byte[])xml.responseBody);
}
return null;
}
#endregion
#region 构造与释构
public XMLHTTP()
{
xml = new XMLHTTPClass();
}
~XMLHTTP()
{
Dispose();
}
protected virtual void Dispose(bool isDisposing)
{
if (_alreadyDispose) return;
if (isDisposing)
{
if (xml != null)
{
xml = null;
}
}
_alreadyDispose = true;
}
#endregion
#region IDisposable 成员
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}
声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com