C#的Http请求
来源:互联网 发布:最优化 中科院 编辑:程序博客网 时间:2024/04/26 07:49
使用WebRequest,HttpWebResponse对象
<span style="font-size:18px;">using System;using System.IO;using System.Net;using System.Text;namespace Enenya.Common{ public class HttpRequestResponse { public string GetHttpRequest(string url,string content) { try { WebRequest request = WebRequest.Create(url); request.ContentType = "text/html; charset=utf-8"; request.Method = "POST"; byte[] by = new UTF8Encoding().GetBytes(content); Stream sm = request.GetRequestStream(); sm.Write(by, 0, by.Length); sm.Flush(); sm.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Encoding encoding = Encoding.GetEncoding("UTF-8"); Stream stream = response.GetResponseStream(); StreamReader streamReader = new StreamReader(stream, encoding); string result = streamReader.ReadToEnd(); streamReader.Close(); stream.Close(); return result; } catch (Exception e) { return ""; } } }}</span>
调用接口,或者请求页面,都可以使用这个http请求
0 0
- C#的Http请求
- C#写的Web Http请求
- C#发送Post方式的Http请求
- Http请求之--C#的HttpWebRequest实现POST方式请求
- C#发送HTTP请求
- C# 发HTTP请求
- C# 发HTTP请求
- C# http post请求
- C#发送 http请求
- c#模拟http请求
- C#发送http请求
- c# http请求类
- C# 模拟 Http 请求
- c# HTTP请求
- C# 模拟http请求
- c#调用HTTP请求
- C#访问HTTP请求
- c#进行http请求
- 用mkfs.jffs2 命令制作jffs2镜像文件
- Rabbit MQ 管理客户端配置
- libvirt网络过滤规则简单总结
- 第四周 项目1-三角形类的构造函数(4)---有默认参数的构造函数
- 阿里巴巴笔试题求最小三元组距离
- C#的Http请求
- 关于编程学习的好网站
- c++获取系统信息(操作系统,cpu,内存,ip,mac)
- const浅析
- shell script简单范例
- iOS判断NSString 只含有数字
- 获取月份天数
- CSU 1552: Friends(素数测试+二分匹配)
- ThreadLocal