C # Request HTTP Address

Source: Internet
Author: User

Using system;using system.io;using system.net;using system.text;public class httputil{Private Const string Scontenttyp    E = "application/x-www-form-urlencoded"; Private Const string suseragent = "mozilla/4.0 (compatible; MSIE 7.0;    Windows NT 5.2;. NET CLR 1.1.4322;. NET CLR 2.0.50727) "; public static string Send (string data, string url) {return Send (encoding.getencoding ("UTF-8").    GetBytes (data), URL);        } public static string Send (byte[] data, string url) {Stream responsestream;        HttpWebRequest request = webrequest.create (URL) as HttpWebRequest; if (request = = null) {throw new ApplicationException (string.        Format ("Invalid URL string: {0}", url)); }//Request.          useragent = suseragent; Request.        ContentType = Scontenttype; Request.        Method = "POST"; Request. ContentLength = data.        Length; Stream requeststream = Request.        GetRequestStream (); requestStream.Write (data, 0, data.   Length);     Requeststream.close (); try {responsestream = Request. GetResponse ().        GetResponseStream ();        } catch (Exception Exception) {throw Exception; } string str = string.        Empty; using (StreamReader reader = new StreamReader (Responsestream, encoding.getencoding ("UTF-8"))) {str = RE Ader.        ReadToEnd ();        } responsestream.close ();    return str; }}

C # Request HTTP Address

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.