The latest project is to provide methods for mobile apps.
Therefore, this method can be used for interface testing
1 Static classHttpClient2 {3 StaticCookiecontainer cookies =NewCookiecontainer ();4 Public Static stringGetWebResponse (stringUrlstringparam)5 {6 stringLoginurl =NewConfig (). Host +URL;7 8 varbytes =Newasciiencoding (). GetBytes (param);9 varRequest =(HttpWebRequest) webrequest.create (loginurl);Ten OneRequest. Method ="POST"; ARequest. ContentType ="application/x-www-form-urlencoded"; -Request. ContentLength =bytes. Length; -Request. Cookiecontainer =cookies; the Try - { - using(Stream stream =request. GetRequestStream ()) - { +Stream. Write (Bytes,0, Bytes. Length); - Stream. Close (); + } A at using(HttpWebResponse response =(HttpWebResponse) request. GetResponse ()) - { -StreamReader reader =NewStreamReader (response. GetResponseStream ()); - varresult =Reader. ReadToEnd (); - Response. Close (); - returnresult; in } - } to Catch(Exception ex) + { - Throw NewAggregateException (ex. ToString ()); the } * } $}
URL Post Request method