http://stackoverflow.com/questions/4015324/http-request-with-post

 Response.Charset = "GBK";  //GBK  //gb2312
this.CodePage = 936;
Session.CodePage = 936;
Encoding myEncoding = Encoding.GetEncoding("GBK");
byte[] data = System.Text.Encoding.GetEncoding("GBK").GetBytes("907953"); //System.Text.UnicodeEncoding.ASCII.GetBytes("135246");//UTF8
Base64Encoder myEncoder = new Base64Encoder(data);
StringBuilder sb = new StringBuilder();
sb.Append(myEncoder.GetEncoded());
string content = HttpUtility.UrlEncode("塗聚文:需要還3本書的時間為:2014-07-12:15:58,csharp", myEncoding);
String sResult = "http://www2.lansea.com.cn/servlet/UserServiceAPI?method=sendSMS&isLongSms=0&username=87&password=232&smstype=0&mobile=13824350518&content=" + content + ""; //string param = HttpUtility.UrlEncode(sResult, myEncoding);
Response.Write(sResult); byte[] postBytes = Encoding.GetEncoding("GBK").GetBytes(sResult); // Encoding.GetEncoding("GBK").GetBytes(sResult);
try
{ HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(sResult);//sResult
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded;charset=GBK";
req.Headers["Accept-Charset"] = "GBK";
req.Headers["Accept-Language"] = "zh-CN,zh;q=0.";
req.AllowAutoRedirect = false;
req.ContentLength = postBytes.Length;
Stream webStream = req.GetRequestStream(); //发送数据
webStream.Write(postBytes, 0, postBytes.Length);
webStream.Close();
//获取返回数据
HttpWebResponse webResponse = (HttpWebResponse)req.GetResponse();
StreamReader reader = new StreamReader(webResponse.GetResponseStream(), Encoding.GetEncoding("GBK"));
sResult = reader.ReadToEnd();
sResult.Trim();
this.TextBox1.Text = sResult;//返回是否发送成功的结果
}
catch (Exception ex)
{
ex.Message.ToString();
//sResult = "";
//return sResult;
}

csharp: HttpWebRequest and HttpWebResponse的更多相关文章

  1. c# HttpWebRequest与HttpWebResponse 绝技(转载)

    c# HttpWebRequest与HttpWebResponse 绝技    如果你想做一些,抓取,或者是自动获取的功能,那么就跟我一起来学习一下Http请求吧.本文章会对Http请求时的Get和P ...

  2. c# HttpWebRequest与HttpWebResponse

    [转]c# HttpWebRequest与HttpWebResponse 绝技 如果你想做一些,抓取,或者是自动获取的功能,那么就跟我一起来学习一下Http请求吧. 本文章会对Http请求时的Get和 ...

  3. C# HttpWebRequest与HttpWebResponse详解

    C# HttpWebRequest与HttpWebResponse详解  http://www.codeproject.com/Articles/6554/How-to-use-HttpWebRequ ...

  4. 使用HttpWebRequest以及HttpWebResponse读取Http远程文件

     主页>杂项技术>.NET(C#)> 使用HttpWebRequest以及HttpWebResponse读取Http远程文件 jackyhwei 发布于 2010-08-15 21: ...

  5. HttpWebRequest和HttpWebResponse用法小结

    http://www.cnblogs.com/willpan/archive/2011/09/26/2176475.html http://www.cnblogs.com/lip0121/p/4539 ...

  6. 利用HttpWebRequest和HttpWebResponse获取Cookie

    之前看过某个同学的一篇有关与使用JSoup解析学校图书馆的文章,仔细一看,发现竟然是同校!!既然对方用的是java,那么我也就来个C#好了,虽然我的入门语言是java. C#没有JSoup这样方便的东 ...

  7. C#模拟POST提交表单(二)--HttpWebRequest以及HttpWebResponse

    上次介绍了用WebClient的方式提交POST请求,这次,我继续来介绍用其它一种方式 HttpWebRequest以及HttpWebResponse 自认为与上次介绍的WebClient最大的不同之 ...

  8. C# 利用 HttpWebRequest 和 HttpWebResponse 模拟登录有验证码的网站

    原文:C# 利用 HttpWebRequest 和 HttpWebResponse 模拟登录有验证码的网站 我们经常会碰到需要程序模拟登录一个网站,那如果网站需要填写验证码的要怎样模拟登录呢?这篇文章 ...

  9. 利用HttpWebRequest和HttpWebResponse获取Cookie并实现模拟登录

    利用HttpWebRequest和HttpWebResponse获取Cookie并实现模拟登录 tring cookie = response.Headers.Get("Set-Cookie ...

随机推荐

  1. UIEvent笔记

    UIEvent是什么 代表iOS系统中的一个事件. UIEvent分为三类,touch events, motion events, and remote-control events touch e ...

  2. 对xaml的深入探究(补交作业)

    首先,下结论,看完那个外国老师的视频后,5%左右听懂了,分享给大家: 1.理解一下,xaml是特殊的xml,我们可以从代码语法看出,xaml中的打码很类似与html和xml的代码. 2.xaml.cs ...

  3. leetcode-680-Valid Palindrome II

    题目描述: Given a non-empty string s, you may delete at most one character. Judge whether you can make i ...

  4. Q767 重构字符串

    给定一个字符串S,检查是否能重新排布其中的字母,使得两相邻的字符不同. 若可行,输出任意可行的结果.若不可行,返回空字符串. 示例 1: 输入: S = "aab" 输出: &qu ...

  5. Git命令之回退篇 git revert git reset

    Git command之回退篇 欲练回退 必先了解:HEAD.index.WorkingCopy HEAD: 当前所在的分支版本顶端的别名,也就是最新的一次commit. git commit 之后与 ...

  6. reset.css(重置浏览器默认样式)

    @charset "utf-8";html{background-color:#fff;color:#000;font-size:12px} body,ul,ol,dl,dd,h1 ...

  7. saltstack源码详解一

    目录 初识源码流程 入口 1.grains.items 2.pillar.items 2/3: 是否可以用python脚本实现 总结pillar源码分析: @(python之路)[saltstack源 ...

  8. 时钟时间,系统cpu时间,用户cpu时间

    进程的3种状态:阻塞,就绪,运行   度量一个进程的执行时间,unix为进程维护了3个时间,即时钟时间,用户CPU时间,系统CPU时间.   时钟时间又被称为墙上时钟时间,wall clock tim ...

  9. Java - 冒泡排序的基础算法(尚学堂第七章数组)

    /** * 冒泡排序的基础算法 */ import java.util.Arrays; public class TestBubbleSort1 { public static void main(S ...

  10. 【随笔】MIME类型

    在openResty作为Web服务器的情况下访问根目录的首页时,出现了这样一个问题: nginx端的配置: worker_processes 2; error_log logs/error.log; ...