Abstract: How to Use asp.net to post a message to other servers
Using System;
Using System. Web;
Using System. Net;
Using System. IO;
Using System. Text;
Namespace SendMessage
{
Public bool SendMsg (MsgInfo msg)
{
// Create request
Try
{
WebRequest req = WebRequest. Create ("http: // your_post_url ");
// Set the request parameter
Req. Method = "POST ";
Req. ContentType = "application/x-www-form-urlencoded ";
// Querystring '? Msg = xxx & type = 0'
String strQuery = "msg = ";
StrQuery + = HttpUtility. UrlEncode (msg );
StrQuery + = "& type = 0 ";
String dataSend = strQuery;
Req. ContentLength = dataSend. Length;
Byte [] buff = Encoding. UTF8.GetBytes (dataSend );
Stream reqStream = req. GetRequestStream ();
ReqStream. Write (buff, 0, buff. Length );
ReqStream. Close ();
WebResponse rep = req. GetResponse ();
Stream repStream = rep. GetResponseStream ();
Encoding enc = Encoding. GetEncoding ("UTF-8 ");
StreamReader sr = new StreamReader (repStream, enc );
Char [] read = new Char [256];
Sr. Read (read, 0,256 );
Return true;
}
Catch (NotSupportedException ns)
{
Return false;
}
}
}