C# 如何发送Http请求
HttpSender是一个用于发送Http消息的轻量C#库,使用非常简单,只需要一两行代码,就能完成Http请求的发送
使用 Nuget,搜索 HttpSender 就能找到这个库
这个库的命名空间是HttpSender,类名是Sender
详细用法:
1. 发送 Get 请求
static string Get(string url)
string Response = Sender.Get("http://localhost:5000/home/info?username=jim");
2. 发送 Post 请求
static string Post(string url,string content)
string Response = Sender.Post("http://localhost:5000/home/login", "username=jim&password=123456");
static string Post(string url, Dictionary<string,string> content)
Dictionary<string, string> LoginInfo = new Dictionary<string, string> { { "username", "jim" }, { "password", "123456" }};string Response = Sender.Post("http://localhost:5000/home/login", LoginInfo);
3. 发送 Put 请求
static string Put(string url)
string Response = Sender.Put("http://localhost:5000/home/update?username=jim&age=15");
static string Put(string url, Dictionary<string,string> content)
Dictionary<string, string> UpdateInfo = new Dictionary<string, string> { { "username", "jim" }, { "age" , "15"}};string Response = Sender.Put("http://localhost:5000/home/update", UpdateInfo);
4. 发送 Delete 请求
static string Delete(string url)
string Response = Sender.Delete("http://localhost:5000/home/delete?username=jim&year=2011");
5. 设置等待时间
static void SetWaitingTime(int milliseconds)
默认等待时间是5000毫秒
Sender.SetWaitingTime();
C# 如何发送Http请求的更多相关文章
- Java发送Http请求并获取状态码
通过Java发送url请求,查看该url是否有效,这时我们可以通过获取状态码来判断. try { URL u = new URL("http://10.1.2.8:8080/fqz/page ...
- AngularJs的$http发送POST请求,php无法接收Post的数据解决方案
最近在使用AngularJs+Php开发中遇到php后台无法接收到来自AngularJs的数据,在网上也有许多解决方法,却都点到即止.多番摸索后记录下解决方法:tips:当前使用的AngularJ ...
- Ajax发送POST请求SpringMVC页面跳转失败
问题描述:因为使用的是SpringMVC框架,所以想使用ModelAndView进行页面跳转.思路是发送POST请求,然后controller层中直接返回相应ModelAndView,但是这种方法不可 ...
- 使用HttpClient来异步发送POST请求并解析GZIP回应
.NET 4.5(C#): 使用HttpClient来异步发送POST请求并解析GZIP回应 在新的C# 5.0和.NET 4.5环境下,微软为C#加入了async/await,同时还加入新的Syst ...
- 在发送ajax请求时加时间戳或者随机数去除js缓存
在发送ajax请求的时候,为了保证每次的都与服务器交互,就要传递一个参数每次都不一样,这里就用了时间戳 大家在系统开发中都可能会在js中用到ajax或者dwr,因为IE的缓存,使得我们在填入相同的值的 ...
- HttpUrlConnection发送url请求(后台springmvc)
1.HttpURLConnection发送url请求 public class JavaRequest { private static final String BASE_URL = "h ...
- kattle 发送post请求
一.简介 kattle是一款国外开源的ETL工具,纯java编写,可以在Window.Linux.Unix上运行,数据抽取高效稳定.它允许你管理来自不同数据库的数据,通过提供一个图形化的用户环境来描述 ...
- 【荐】怎么用PHP发送HTTP请求(POST请求、GET请求)?
file_get_contents版本: <?php /** * 发送post请求 * @param string $url 请求地址 * @param array $post_data pos ...
- 使用RestTemplate发送post请求
最近使用RestTemplate发送post请求,遇到了很多问题,如转换httpMessage失败,中文乱码等,调了好久才找到下面较为简便的方法: RestTemplate restTemplate ...
- 【转载】JMeter学习(三十六)发送HTTPS请求
Jmeter一般来说是压力测试的利器,最近想尝试jmeter和BeanShell进行接口测试.由于在云阅读接口测试的过程中需要进行登录操作,而登录请求是HTTPS协议.这就需要对jmeter进行设置. ...
随机推荐
- codeforces 688D D. Remainders Game(中国剩余定理)
题目链接: D. Remainders Game time limit per test 1 second memory limit per test 256 megabytes input stan ...
- 洛谷P3243 [HNOI2015]菜肴制作——拓扑排序
题目:https://www.luogu.org/problemnew/show/P3243 正向按字典序拓扑排序很容易发现是不对的,因为并不是序号小的一定先做: 但若让序号大的尽可能放在后面,则不会 ...
- HTML标签防XSS攻击过滤模块--待优化
HTML标签防XSS攻击过滤模块 http://cnodejs.org/topic/5058962f8ea56b5e7806b2a3
- SpringMVC数据绑定四(自定义的类型转换器)
1.PropertyEditor 继承PropertyEditorSupport //controller @Controller public class TestController extend ...
- SpringMVC数据绑定三(JSON 、XML))
dhc chrome 地址https://chrome.google.com/webstore/detail/restlet-client-rest-api-t/aejoelaoggembcahagi ...
- Ubuntu 12.04的gnome classic panel添加程序快捷键(转载)
How to add applets to the Gnome classic panel in Ubuntu 12.04 转自:http://www.borfast.com/blog/how-add ...
- Akka源码分析-Serialization
今天我们来谈一下akka的序列化框架,其实序列化.反序列化是一个老生常谈的问题,那么我们为什么还要研究一下akka的序列化框架呢?不就是使用哪种序列化.反序列化方法的区别么?其实刚开始的时候我也是这么 ...
- UVA 10462 Is There A Second Way Left? (次小生成树+kruskal)
题目大意: Nasa应邻居们的要求,决定用一个网络把大家链接在一起.给出v个点,e条可行路线,每条路线分别是x连接到y需要花费w. 1:如果不存在最小生成树,输出“No way”. 2:如果不存在次小 ...
- 如何用PS快速做出3D按钮效果的图片
1 先建立一个透明图层 2:再创建一个矩形 3:选用过喷样式 4: 双击图层并应用蓝色,记得这里应该复制下颜色的16进制值. 效果如图所示 取消光泽选项,大功告成! 最终效果如图所示,将其保存为PNG ...
- c#如何使用replace函数将"\"替换成"\\"
当我使用 String str="c:\aa.xls"; str=str.Replace("\","\\");时,括号为红色错误的,那么如何 ...