C#发送HTTP POST请求和响应POST请求
来源:互联网 发布:国美容美发软件下载 编辑:程序博客网 时间:2024/04/28 19:58
发送请求:
private void button1_Click(object sender, EventArgs e)
{
string sUrl = txtUrl.Text;
string sParam = postParam.Text;
HttpWebRequest req = WebRequest.Create(sUrl) as HttpWebRequest;
if (req != null)
{
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] postData = Encoding.GetEncoding("UTF-8").GetBytes(sParam);
if (postData.Length > 0)
{
req.ContentLength = postData.Length;
req.Timeout = 15000;
Stream outputStream = req.GetRequestStream();
outputStream.Write(postData, 0, postData.Length);
outputStream.Flush();
outputStream.Close();
try
{
req.GetResponse();
}
catch (Exception ex)
{
}
}
}
}
响应请求:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
System.IO.Stream s = Request.InputStream;
int count = 0;
byte[] buffer = new byte[1024];
StringBuilder builder = new StringBuilder();
while ((count = s.Read(buffer, 0, 1024)) > 0)
{
builder.Append(Encoding.UTF8.GetString(buffer, 0, count));
}
s.Flush();
s.Close();
s.Dispose();
string PostData = builder.ToString();
}
catch (Exception ex)
{ throw ex; }
}
}
- C#发送HTTP POST请求和响应POST请求
- Apache http 发送post请求,解析响应
- http 发送post请求
- C# 发送POST请求
- c#发送http请求get post
- C#发送Post方式的Http请求
- C# Http 发送Post请求实例
- 缓存 HTTP POST请求和响应
- HTTP请求与响应-get和post
- C# http post请求
- ios发送http GET和POST请求
- java发送http get 和 post 请求
- Http--发送 POST 和 GET 请求
- HTTP客户端发送Post和Get请求
- c# 发送GET 和 POST请求
- http请求(get 和 post 请求)与响应
- Http post请求发送示例
- python 发送http post请求
- 百度地图api
- C++ primer plus 第六版 课后答案 8.7
- uva10791 Minimum Sum LCM
- 使用CF Cli发布应用Spring Music
- LR监控Linux系统性能计数器详解
- C#发送HTTP POST请求和响应POST请求
- Centos7配置本地yum
- turn off x-window
- android上传图片到服务器(使用base64字节流的形式通过 AsyncHttpClient框架传输)
- Web文件批量上传控件-Xproer.HttpUploader发布
- echarts图表demo
- Sql server对表中数据进行排序,并将序号更新至列
- 黑马程序员——IO第三天
- poj 3368(RMQ)