zoukankan      html  css  js  c++  java
  • ASP.Net Post方式获取数据流的一种简单写法

     public static string PostWebReq(string PostUrl, string ParamData, Encoding DataEncode)
            {
                string ret = string.Empty;
                try
                {
                    byte[] byteArray = DataEncode.GetBytes(ParamData);
                    HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(PostUrl));
                    webReq.Method = "POST";
                    webReq.ContentType = "application/x-www-form-urlencoded";
                    webReq.ContentLength = byteArray.Length;

                    Stream newStream = webReq.GetRequestStream();
                    newStream.Write(byteArray, 0, byteArray.Length);
                    newStream.Close();

                    HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
                    StreamReader sr = new StreamReader(response.GetResponseStream(), DataEncode);
                    ret = sr.ReadToEnd();

                    sr.Close();
                    response.Close();
                    newStream.Close();
                }
                catch (WebException ex)
                {
                  //  Log.WriteLog(LogFile.Error, ex.Message);
                }
                finally
                {
                  //  Log.WriteLog(LogFile.Info, ret);
                }
                return ret;
            }

    萌橙 你瞅啥?
  • 相关阅读:
    OC面向对象—封装
    设计模式之类关系
    理性:中国别一厢情愿救俄罗斯(转)
    Mockito--完整功能介绍(转)
    从陌陌上市看BAT的移动保卫战(转)
    This exception may occur if matchers are combined with raw values
    RepositoryClassLoader.java
    搭建你的持续集成server
    mysql中怎样查看和删除唯一索引
    Android中Context具体解释 ---- 你所不知道的Context
  • 原文地址:https://www.cnblogs.com/daimaxuejia/p/7199006.html
Copyright © 2011-2022 走看看