Copy Code code as follows:
/****************************************************************
* Function Name: SendCommand (Sendmethod method, St_param p)
* Function Description: Send the URL and parameters to the remote, accept the return information (no garbled);
* Parameter: Method:xml send method, post/get two kinds
P: Parametric structural body
public string Url; Remote URL
public string Parameters; Parameters
public string Uid; Account
public string Pwd; Command
* Call Columns:
* Using EBCNC; Reference Space Name
* XMLHTTP x = new XMLHTTP (); The XMLHTTP of creating construction
* XMLHTTP. St_param st = new XMLHTTP. St_param (); Creating an array of parameters
* St. Parameters = ""; URL Detail Parameters
* St. URL = "http://www.baidu.com/"; Url
* St. Uid = ""; Account
* St. PWD = ""; Password
* String rn= ""; return string
* Rn=x.sendcommand (XMLHTTP. Sendmethod.post, ST); Get return information
* X.dispose ();
***********************************************************************/
Using System;
Using MSXML2;
Namespace EBCNC
{
<summary>
XMLHTTP base class
</summary>
public class Xmlhttp:idisposable
{
#region Variables and parameters
Private Xmlhttpclass XML;
private bool _alreadydispose = false;
Public St_param Parameters;
public enum Sendmethod:int
{
POST, get
}
#endregion
#region parameter Structural body
public struct St_param
{
public string Url;
public string Parameters;
public string Uid;
public string Pwd;
}
#endregion
#region Send data
<summary>
Send data
</summary>
<param name= "Method" > Delivery </param>
<param name= "P" > Data </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 structure and its interpretation
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 Members
public void Dispose ()
{
Dispose (TRUE);
Gc. SuppressFinalize (this);
}
#endregion
}
}