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

     1 private string PostData(string url, string postData)
     2 {
     3     ASCIIEncoding encoding = new ASCIIEncoding();
     4     byte[] data = encoding.GetBytes(postData);
     5     HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
     6 
     7     myRequest.Method = "POST";
     8     myRequest.ContentType = "application/x-www-form-urlencoded";
     9     myRequest.ContentLength = data.Length;
    10     Stream newStream = myRequest.GetRequestStream();
    11 
    12     newStream.Write(data, 0, data.Length);
    13     newStream.Close();
    14 
    15     HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
    16     StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);
    17     string content = reader.ReadToEnd();
    18     reader.Close();
    19     return content;
    20 }
    21 
    22 private string GetData(string url)
    23 {
    24     HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
    25     myRequest.Method = "GET";
    26     HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
    27     StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
    28     string content = reader.ReadToEnd();
    29     reader.Close();
    30     return content;
    31 }
    View Code
  • 相关阅读:
    领域驱动设计ddd
    LayUI
    Kendo框架
    mysql rdms 笔记
    window系统安装mysql
    在VS项目中通过GIT生成版本号作为编译版本号
    在VS项目中使用SVN版本号作为编译版本号
    Oracle与SQL SERVER编程差异分析(入门)
    发布MeteoInfo 3.0
    Tomcat7 安全部署配置修改
  • 原文地址:https://www.cnblogs.com/kkwoo/p/3787835.html
Copyright © 2011-2022 走看看