zoukankan      html  css  js  c++  java
  • HttpWebRequest

    HttpWebRequest request;
    HttpWebResponse response;
    ASCIIEncoding encoding = new ASCIIEncoding();
    request = WebRequest.Create(postUrl) as HttpWebRequest;
    byte[] b = encoding.GetBytes(postUrl);
    request.UserAgent = "Mozilla/4.0";
    request.Method = "PUT";
    request.ContentLength = b.Length;
    using (Stream stream = request.GetRequestStream())
    {
    stream.Write(b, 0, b.Length);
    }
    try
    {
    //获取服务器返回的资源
    response = request.GetResponse() as HttpWebResponse;
    using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
    {
    string result = reader.ReadToEnd();
    if (result.Trim().Length == 0)
    {
    textBox2.Text = "执行成功,但未检测到任何返回信息!";
    }
    else
    {
    textBox2.Text = result;
    }
    }
    }
    catch (WebException ex)
    {
    textBox2.Text = ex.ToString();
    }

    HttpWebRequest request;
    HttpWebResponse response;
    request = WebRequest.Create(postUrl) as HttpWebRequest;
    request.Method = "GET";
    request.UserAgent = "Mozilla/4.0";
    request.KeepAlive = true;
    response = (HttpWebResponse)request.GetResponse();
    StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
    string result = reader.ReadToEnd();
    if (result.Trim().Length == 0)
    {
    textBox2.Text = "执行成功,但未检测到任何返回信息!";
    }
    else
    {
    textBox2.Text = result;
    }

    只想一个人飞----奔跑的孩子
    个人博客地址:http://www.microyang.cn
  • 相关阅读:
    CQUOJ 10819 MUH and House of Cards
    CQUOJ 9920 Ladder
    CQUOJ 9906 Little Girl and Maximum XOR
    CQUOJ 10672 Kolya and Tandem Repeat
    CQUOJ 9711 Primes on Interval
    指针试水
    Another test
    Test
    二分图匹配的重要概念以及匈牙利算法
    二分图最大匹配
  • 原文地址:https://www.cnblogs.com/liyangLife/p/3746084.html
Copyright © 2011-2022 走看看