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. JMeter的基本介绍和入门

    1. 介绍 JMeter是Apache组织的开放源代码项目,能做功能测试和性能测试.它能够对HTTP和FTP服务器进行压力和性能测试,也可以对任何数据库进行同样的测试(通过JDBC),还能以多种形式展 ...

  2. Android框架之网络开发框架Volley

    1. Volley简单介绍 我们平时在开发Android应用的时候不可避免地都须要用到网络技术.而多数情况下应用程序都会使用HTTP协议来发送和接收网络数据.Android系统中主要提供了两种方式来进 ...

  3. [Java Performance] 数据库性能最佳实践 - JPA和读写优化

    数据库性能最佳实践 当应用须要连接数据库时.那么应用的性能就可能收到数据库性能的影响. 比方当数据库的I/O能力存在限制,或者因缺失了索引而导致运行的SQL语句须要对整张表进行遍历.对于这些问题.只相 ...

  4. cookie记录浏览记录

    cookie记录浏览记录 HashMap也是我们使用非常多的Collection,它是基于哈希表的 Map 接口的实现,以key-value的形式存在.在HashMap中,key-value总是会当做 ...

  5. 基于 CoreText 实现的高性能 UITableView

    引起UITableView卡顿比较常见的原因有cell的层级过多.cell中有触发离屏渲染的代码(譬如:cornerRadius.maskToBounds 同时使用).像素是否对齐.是否使用UITab ...

  6. oracle数据库使用之数据查询入门

    1.在查询过程中使用算术表达式对数据进行运算 student表结构如下: 最后一项salary表示每个人的月薪,我现在想查询每个人的年薪: 2.使用nvl函数处理null值,向表中插入一条数据,该数据 ...

  7. Ⅴ.AngularJS的点点滴滴-- 资源和过滤

    资源ngResource(依赖ngResource模块) <html> <script src="http://ajax.googleapis.com/ajax/libs/ ...

  8. 高效 jquery 的奥秘

    当你准备使用 jQuery,我强烈建议你遵循下面这些指南: 1. 缓存变量 DOM 遍历是昂贵的,所以尽量将会重用的元素缓存. // 糟糕 h = $('#element').height(); $( ...

  9. Windows2012中Python2.7.11+Python3.4.4+Pycharm

    下载软件包 Python2.7.11:  https://www.python.org/ftp/python/2.7.11/python-2.7.11.amd64.msi Python3.4.4:   ...

  10. CentOS 6.7编译安装PHP7

    1.首先配置好编译环境 yum update && yum upgrade yum groupinstall "Development Tools" yum ins ...