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. C#常用工具类——Excel操作类

    /// 常用工具类——Excel操作类 /// <para> ------------------------------------------------</para> / ...

  2. C#基础知识—父类和子类的关系

    基础知识一: using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms ...

  3. Velocity源码分析

    velocity模板渲染的步骤: 1) 首先初始化启动Velocity引擎,可以通过Velocity.init()或者新建VelocityEngine类,并调用其中的init()方法: 2) 创建一个 ...

  4. cf 85 E. Petya and Spiders

    http://codeforces.com/contest/112/problem/E 轮廓线dp.每一个格子中的蜘蛛选一个去向.终于,使每一个蜘蛛都有一个去向,同一时候保证有蜘蛛的格子最少.须要用4 ...

  5. android 60 发送短信

    import android.os.Bundle; import android.app.Activity; import android.telephony.SmsManager; import a ...

  6. VS中新建网站和新建项目web应用程序的区别?(实际应用总结一点)

    1,在网站中是没有命名空间namespace这个概念的.例如公共类只有放在App_Code里(不但是公共类,所有的类都应放在这里),其他的类或者页面才可以引用.有using这个概念,但没有namesp ...

  7. width:100% 和 max-width:100%; 有区别吗【转藏】

    这个博客是基于“Pelican+Markdown+定制的my-gum主题”的.定制的主题将博文正文页面的 右边栏去掉,这导致在Firefox等浏览器中,正文中大的图片会突破正文块的宽度,高度也得不到限 ...

  8. WisDom.Net 框架设计(六) license

    WisDom.Net-license 1.为啥要用license    license (许可证) 顾名思义就是说我的软件只能给在指定的机器上使用.毕竟很多项目都不是免费的,(说句题外话,其实我用的也 ...

  9. 在picture library中取某一图片的大图、小图

    public static string GetPicThumbnail(SPFile file, string type) {     string thumbnail = "" ...

  10. Eclipse闪退/打不开/无法启动/一闪而过

    转自:http://my.oschina.net/psuyun/blog/421058 很长时间了,写java.写android都是用的Eclipse.可是突然有一天,当我像往常一样试图打开Eclip ...