Using system.collections.generic;using system.linq;using system.text;using system.net;using System.IO;using System; Namespace KL. EDMS. business.report{public class Faultcountlogic {//NOTE: This request pushes public a message to the client in order to send a request to Androidpnserver Stri Ng Senthttprequest () {//request path String url = "Http://localhost:7070/notification.do"; Define the request and set the path to the request WebRequest request = WebRequest.Create (URL); Defines the way the request is requested. Method = "POST"; Initialize the request parameter string postdata = "action=send&broadcast=y&uri=112332&username=f8df247d0b2b4277b122f 68c94c2caab "; PostData + = "&title=c# send background request"; PostData + = "&message= uses the C # background to send HTTP requests to Androidpnserver to implement client-side message push functionality. "; Set parameter encoding format, solve Chinese garbled byte[] ByteArray = Encoding.UTF8.GetBytes (postdata); Set the MIME type and content length of the request RequesT.contenttype = "application/x-www-form-urlencoded"; Request. ContentLength = Bytearray.length; Open the request character stream stream DataStream = Request. GetRequestStream (); Datastream.write (ByteArray, 0, bytearray.length); Datastream.close (); Define response for the preceding request response WebResponse response = Request. GetResponse (); Gets the corresponding status code Console.WriteLine (((HttpWebResponse) response). Statusdescription); Defines the response character stream dataStream = response. GetResponseStream (); StreamReader reader = new StreamReader (dataStream); String responsefromserver = reader. ReadToEnd ();//Read All Console.WriteLine (Responsefromserver); Close resource reader. Close (); Datastream.close (); Response. Close (); return responsefromserver; } }}
C # background Send HTTP request