For details about how to use httpwebrequest, refer to msdn and my other article.
This example is just an example where a client initiates a request and the server simply processes the request.
Client request
String reqestmsg = "Tom"; string responsemsg = string. empty; byte [] buffer = encoding. utf8.getbytes (reqestmsg); try {// change the request address to the blog garden, such as the http://www.cnblogs.com, and return the whole page data httpwebrequest request = (httpwebrequest) webrequest. create ("http: // localhost: 6603/webserver. aspx "); Request. method = "Post"; request. contentlength = buffer. length; using (Stream requeststream = request. getrequeststream () {requeststream. write (buffer, 0, buffer. length);} httpwebresponse resonse = (httpwebresponse) request. getresponse (); stream responsestream = resonse. getresponsestream (); Using (streamreader sr = new streamreader (responsestream) {responsemsg = sr. readtoend ();} resonse. close ();} catch (exception ex) {responsemsg = ex. message;} response. write (responsemsg );
Server
string responseMsg = "NO MSG"; if (Request.InputStream != null) { byte[] buffer = new byte[Request.InputStream.Length]; Request.InputStream.Read(buffer, 0, buffer.Length); string msg = Encoding.UTF8.GetString(buffer); msg = msg.Replace("+", "%2B").Replace(" ", "%20"); responseMsg = SayHello(msg); } Response.Write(responseMsg);