How to use ASP.NET to other servers POST a message

xiaoxiao2021-03-06  118

Www.chinacs.net Chinese C # Technology Station

Using system;

Using system.Web;

Using system.net;

Using system.io;

Using system.text;

Namespace SendMessage

{

Public Bool Sendmsg (MsgInfo Msg) {// CREATE RequestTry {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.getResponseSte_; 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;}}

}

转载请注明原文地址:https://www.9cbs.com/read-100091.html

New Post(0)