. Net request Web interface post and Get methods

Source: Internet
Author: User

#region Web Service Request get post
static string defaultuseragent = "www.zhiweiworld.com";
public static string Get (string url)
{
System.Net.HttpWebRequest request = System.Net.WebRequest.Create (URL) as System.Net.HttpWebRequest;
Request. Method = "GET";
Request. useragent = defaultuseragent;
System.Net.HttpWebResponse result = Request. GetResponse () as System.Net.HttpWebResponse;
System.IO.StreamReader sr = new System.IO.StreamReader (result. GetResponseStream (), Encoding.UTF8);
String strresult = Sr. ReadToEnd ();
Sr. Close ();
Console.WriteLine (strresult);
return strresult;
}

public static string Post (string URL, System.Collections.Specialized.NameValueCollection para)
{
System.Net.WebClient webclientobj = new System.Net.WebClient ();

byte[] byremoteinfo = webclientobj.uploadvalues (URL, "POST", para);//Request address, method of argument, parameter set

String rtcontent = System.Text.Encoding.UTF8.GetString (byremoteinfo);//Get return value
return rtcontent;
}
#endregion

. Net request Web interface post and Get methods

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.