zoukankan      html  css  js  c++  java
  • C# 后台POST和GET 获取数据

     C# 后台POST和GET 获取数据

    private string PostData(string url, string postData)
    {
        ASCIIEncoding encoding = new ASCIIEncoding();
        byte[] data = encoding.GetBytes(postData);
        HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);

        myRequest.Method = "POST";
        myRequest.ContentType = "application/x-www-form-urlencoded";
        myRequest.ContentLength = data.Length;
        Stream newStream = myRequest.GetRequestStream();

        newStream.Write(data, 0, data.Length);
        newStream.Close();

        HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
        StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);
        string content = reader.ReadToEnd();
        reader.Close();
        return content;
    }

    private string GetData(string url)
    {
        HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
        myRequest.Method = "GET";
        HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
        StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
        string content = reader.ReadToEnd();
        reader.Close();
        return content;
    }
  • 相关阅读:
    triangle
    Synchronizing timer
    jenkins 安装网址
    Java I/O编程思路
    SpEL快速入门
    Spring ApplicationContext的事件机制
    畅谈Spring设计哲学
    Spring ApplicationContext的国际化支持
    SQL中 WHERE与HAVING的区别
    Hibernate的查询语言之HQL(二)——Hibernate查询的from字句
  • 原文地址:https://www.cnblogs.com/wolfocme110/p/3975270.html
Copyright © 2011-2022 走看看