csharp: HttpWebRequest and HttpWebResponse
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的更多相关文章
- c# HttpWebRequest与HttpWebResponse 绝技(转载)
c# HttpWebRequest与HttpWebResponse 绝技 如果你想做一些,抓取,或者是自动获取的功能,那么就跟我一起来学习一下Http请求吧.本文章会对Http请求时的Get和P ...
- c# HttpWebRequest与HttpWebResponse
[转]c# HttpWebRequest与HttpWebResponse 绝技 如果你想做一些,抓取,或者是自动获取的功能,那么就跟我一起来学习一下Http请求吧. 本文章会对Http请求时的Get和 ...
- C# HttpWebRequest与HttpWebResponse详解
C# HttpWebRequest与HttpWebResponse详解 http://www.codeproject.com/Articles/6554/How-to-use-HttpWebRequ ...
- 使用HttpWebRequest以及HttpWebResponse读取Http远程文件
主页>杂项技术>.NET(C#)> 使用HttpWebRequest以及HttpWebResponse读取Http远程文件 jackyhwei 发布于 2010-08-15 21: ...
- HttpWebRequest和HttpWebResponse用法小结
http://www.cnblogs.com/willpan/archive/2011/09/26/2176475.html http://www.cnblogs.com/lip0121/p/4539 ...
- 利用HttpWebRequest和HttpWebResponse获取Cookie
之前看过某个同学的一篇有关与使用JSoup解析学校图书馆的文章,仔细一看,发现竟然是同校!!既然对方用的是java,那么我也就来个C#好了,虽然我的入门语言是java. C#没有JSoup这样方便的东 ...
- C#模拟POST提交表单(二)--HttpWebRequest以及HttpWebResponse
上次介绍了用WebClient的方式提交POST请求,这次,我继续来介绍用其它一种方式 HttpWebRequest以及HttpWebResponse 自认为与上次介绍的WebClient最大的不同之 ...
- C# 利用 HttpWebRequest 和 HttpWebResponse 模拟登录有验证码的网站
原文:C# 利用 HttpWebRequest 和 HttpWebResponse 模拟登录有验证码的网站 我们经常会碰到需要程序模拟登录一个网站,那如果网站需要填写验证码的要怎样模拟登录呢?这篇文章 ...
- 利用HttpWebRequest和HttpWebResponse获取Cookie并实现模拟登录
利用HttpWebRequest和HttpWebResponse获取Cookie并实现模拟登录 tring cookie = response.Headers.Get("Set-Cookie ...
随机推荐
- 性能分析工具VisualVM for eclipse安装过程总结
Java VisualVM Java VisualVM is a tool that provides a visual interface for viewing detailed informat ...
- 线上CPU100%?看看这篇是怎么排查的!
前言 作为后端开发工程师,当收到线上服务器CPU负载过高告警时,你会这么做?重启服务,忽略告警?不过在我看来一个合格的工程师是一定要定位到具体问题所在的,从而 fix 它.下面记录一下线上服务器 CP ...
- 方法引用(Method reference)和invokedynamic指令详细分析
方法引用(Method reference)和invokedynamic指令详细分析 invokedynamic是jvm指令集里面最复杂的一条.本文将详细分析invokedynamic指令是如何实现方 ...
- leetcode-198-House Robber(动态规划)
题目描述: You are a professional robber planning to rob houses along a street. Each house has a certain ...
- USART列子
#include "stm32f10x.h" void USART_INit(void) { GPIO_InitTypeDef GPIO_Initstructe; USART_In ...
- 达人篇:3.1.3)FAI 首件检验
本章目的:了解FAI. 1)定义: FAI: First Article Inspection Report . 汉语译作:首件全尺寸检验报告. 2)目的 制作FAI报告是为了检查成型后的产品尺寸是否 ...
- Vue.js路由跳转带参数到模板组件。
从SalesOrderQuery组件跳到SalesOrder组件,并且通过params属性携带数据. handleClick(row) { //alert(row.FSaleName);//获取该行F ...
- 配置idea解决乱码
在项目开发过程中,我们一般希望在修改完代码之后不重启项目即可提现出修改的结果,那么热部署项目就显得十分必要了.在idea中将项目热部署至tomcat中的方法如下: 首先打开tomcat配置界面,在se ...
- FormsAuthentication实现登录(转)
配置项描述: <authentication mode="Forms"> <forms name=".ASPXAUTH" loginUrl=& ...
- object与byte[]的相互转换、文件与byte数组相互转换
转载自 https://blog.csdn.net/scimence/article/details/52233656 object与byte[]互转 /// <summary> // ...