using System.IO;
using System.Net;

/// <summary>
        /// HttpWebRequest发送Post请求
     /// </summary>
     /// <param name="postUrl"></param>
     /// <param name="paramData"></param>
     /// <param name="dataEncode"></param>
     /// <returns></returns>
        public static string PostWebRequest(string postUrl, string paramData, Encoding dataEncode)
        {
            string ret = string.Empty;
            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();
            return ret; }
       /// <summary>
        /// WebClient发送Get请求,编码UTF8
       /// </summary>
       /// <param name="Url"></param>
       /// <returns></returns>
        public static string Get(string Url) {
            string result = "";
      
            HttpWebRequest httpReq;
            httpReq = (HttpWebRequest)WebRequest.Create(new Uri(Url));
            WebResponse wr = httpReq.GetResponse();
            Stream responseStream = wr.GetResponseStream();
            StreamReader respStreamReader = new StreamReader(responseStream);
            result = respStreamReader.ReadToEnd();
            responseStream.Dispose(); wr.Dispose();
            return result;
        }

随机推荐

  1. Java中List和ArrayList的区别(转)

    List是一个接口,而ListArray是一个类.  ListArray继承并实现了List.  所以List不能被构造,但可以向上面那样为List创建一个引用,而ListArray就可以被构造.  ...

  2. Linux命令之ssh

    一. 配置ssh 1. 命令 ssh-keygen [选项] 2. 说明 用于为“ssh”生成.管理和转换认证密钥,它支持RSA和DSA两种认证密钥 3. 选项 -C:添加注释 -f:指定用来保存密钥 ...

  3. 5 Common Interview Mistakes that Could Cost You Your Dream Job (and How to Avoid Them)--ref

    There have been many articles on our site on software testing interviews. That is because, we, as IT ...

  4. SDWebImage 原理及使用

    这个类库提供一个UIImageView类别以支持加载来自网络的远程图片.具有缓存管理.异步下载.同一个URL下载次数控制和优化等特征. SDWebImage 加载图片的流程 入口 setImageWi ...

  5. Android 自定义View修炼-自定义HorizontalScrollView视图实现仿ViewPager效果

    开发过程中,需要达到 HorizontalScrollView和ViewPager的效果,于是直接重写了HorizontalScrollView来达到实现ViewPager的效果. 实际效果图如下: ...

  6. 前后端分离--mock

    fekit mock 数据 > fekit server -m mock.config 配置mock.config 支持正则 module.exports = { /queryProductDe ...

  7. 移动设备日期选择插件(基于JQUERY)

    上周花了2个小时写的一个日期选择插件,比较适合移动端的设备.先看个效果图吧.如果刚好是你需要的就往下吧,不需要的也可以继续..... 其实网络上已经有的了类似的成熟插件,比如基于mobiscroll, ...

  8. bootstrap 笔记01

    bootstrap源码样式: 移除body的margin声明设置body的背景色为白色为排版设置了基本的字体.字号和行高设置全局链接颜色,且当链接处于悬浮“:hover”状态时才会显示下划线样式 1, ...

  9. PGsql解决时差24H

    SELECT sa_ed_time, sa_st_time, case when sa_ed_time > sa_st_time then extract(EPOCH FROM (sa_ed_t ...

  10. AutoResetEvent 详解

    AutoResetEvent 允许线程通过发信号互相通信.通常,此通信涉及线程需要独占访问的资源. 线程通过调用 AutoResetEvent 上的 WaitOne 来等待信号.如果 AutoRese ...