CopyCode The Code is as follows: /*************************************** *************************
* Function name: sendcommand (sendmethod method, st_param P)
* Function Description: Send a URL and parameter to the remote server and receive the returned information (without garbled characters );
* Parameter: Method: XML sending method, post/get
P: parameter struct
Public String URL; // remote URL
Public String parameters; // Parameter
Public String uid; // account
Public String PWD; // number order
* Call display column:
* Using ebcnc; // name of the referenced Space
* XMLHTTP x = new XMLHTTP (); // create an XMLHTTP object
* XMLHTTP. st_param ST = new XMLHTTP. st_param (); // create a parameter Array
* St. Parameters = ""; // detailed URL parameters
* St. url = "http://www.baidu.com/"; // URL
* St. uid = ""; // account
* St. Pwd = ""; // Password
* String Rn = "; // returns the string
* Rn = x. sendcommand (XMLHTTP. sendmethod. Post, St); // obtain the returned 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 struct
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"> sending method </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 construction and 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 Member
Public void dispose ()
{
Dispose (true );
GC. suppressfinalize (this );
}
# Endregion
}
}