HttpUtil.HttpGet C# (CSharp) Method

HttpGet() public static method

发生get请求
public static HttpGet ( string Url, string postDataStr ) : string
Url string
postDataStr string
return string
    public static string HttpGet(string Url, string postDataStr)
    {
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr);
        request.Method = "GET";
        request.ContentType = "text/html;charset=UTF-8";

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        Stream myResponseStream = response.GetResponseStream();
        StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
        string retString = myStreamReader.ReadToEnd();
        myStreamReader.Close();
        myResponseStream.Close();

        return retString;
    }

Usage Example

Exemplo n.º 1
0
        private void button_get_Click(object sender, EventArgs e)
        {
            //string getdata = string.Format("wkds_id={0}&file_size={1}&thumb_id={2}", "1", "1024", "123456789");
            string strUrl  = this.comboBox_url.Text.Trim();
            string getdata = this.richTextBox_data.Text.Trim();

            this.richTextBox_ack.Text = htmlutil.HttpGet(strUrl, getdata);
        }
All Usage Examples Of HttpUtil::HttpGet