博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
.Net 请求Web接口Post和Get方法
阅读量:7094 次
发布时间:2019-06-28

本文共 921 字,大约阅读时间需要 3 分钟。

#region web服务请求 get post

static string DefaultUserAgent = "www.zhiweiworld.com";
public static String Get(string url)
{
System.Net.HttpWebRequest request = System.Net.WebRequest.Create(url) as System.Net.HttpWebRequest;
request.Method = "GET";
request.UserAgent = DefaultUserAgent;
System.Net.HttpWebResponse result = request.GetResponse() as System.Net.HttpWebResponse;
System.IO.StreamReader sr = new System.IO.StreamReader(result.GetResponseStream(), Encoding.UTF8);
string strResult = sr.ReadToEnd();
sr.Close();
//Console.WriteLine(strResult);
return strResult;
}

public static String Post(string url, System.Collections.Specialized.NameValueCollection para)

{
System.Net.WebClient WebClientObj = new System.Net.WebClient();

byte[] byRemoteInfo = WebClientObj.UploadValues(url, "POST", para);//请求地址,传参方式,参数集合

string rtContent = System.Text.Encoding.UTF8.GetString(byRemoteInfo);//获取返回值 

return rtContent;
}
#endregion

转载地址:http://lkaql.baihongyu.com/

你可能感兴趣的文章
Apache 不能列目录解决。
查看>>
如何永久的修改主机名
查看>>
NSSearchPathForDirectoriesInDomains用法(后台缓存)
查看>>
Jqurey 全选和全不选
查看>>
ELK日志收集平台部署
查看>>
软件公司员工辞职、人员流动大是必然
查看>>
Ubuntu或debian下彻底卸载两步!!
查看>>
9月15日 sed
查看>>
我的友情链接
查看>>
Netlink Socket
查看>>
wordpress服务器安装与响应式网站配置
查看>>
VMware从初级到高级全攻略电子教程
查看>>
less引用其他less文件
查看>>
SQL Server Profiler – 存储过程调试
查看>>
在AWS的EU区域地理位置上分布式MongoDB集群
查看>>
在远程计算机运行PowerShell命令
查看>>
大道至简
查看>>
jdk安装问题
查看>>
系统镜像备份还原Windows 10 系统
查看>>
我的友情链接
查看>>