|
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; } }
} |