C # POST Request HttpWebRequest

Source: Internet
Author: User

Body is the parameter to be passed, the format "roleid=1&uid=2"
Post Cotenttype fill in:
Soap fills in: "Text/xml; Charset=utf-8 "

        public  string posthttp (string url, string body, string contentType)         {            HttpWebRequest HttpWebRequest = (HttpWebRequest) webrequest.create (URL) ;             Httpwebrequest.contenttype = contenttype;        &NBS P   Httpwebrequest.method = "POST";            Httpwebrequest.timeout = 20000; &nbs P           byte[] Btbodys = Encoding.UTF8.GetBytes (body);            Httpwebrequest.contentlength = btbodys.length;            Httpwebrequest.getrequeststream (). Write (Btbodys, 0, Btbodys.length);             HttpWebResponse HttpWebResponse = (Http WebResponse) HttpWebRequest.GetResponse ();            StreamReader StreamReader = new StreamReader (HttpWebResponse. GetResponseStream ());            String responsecontent = Streamreader.readtoend ();              httpwebresponse.close ();            STREAMREADER.C Lose ();            Httpwebrequest.abort ();            HTTPWEBR Esponse. Close ();             return responsecontent;       }

C # POST request HttpWebRequest

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.