星空网 > 软件开发 > ASP.net

本地测试IIS,Post调用接口

最近在学习三种调用接口方式,POST,Socket,Webserivce,今天刚写完POST方式所以就分享下,欢迎高手指点。

public string strResult = "";
protected void Page_Load(object sender, EventArgs e)
{
MyResponseList("发送是否成功");
}
public void MyResponseList(string Charset)
{


try
{
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byteArray = encoding.GetBytes(Charset);
//入口地址 可以传参数
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri("http://192.168.16.39:808/Default.aspx?num=3&&name=broueli"));
webReq.Method = "POST";
webReq.ContentType = "application/x-www-form-urlencoded";
webReq.ContentLength = byteArray.Length;

//获取请求对象
Stream newStream = webReq.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);//写入参数
newStream.Close();
//返回Internet响应
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
string encod = response.ContentEncoding;

//判断是否获取到编码方式
if (encod == null || encod.Length < 1)
{
encod = "UTF-8";
}
//读取流,该流用于读取来自服务器响应体,Encoding 可以直接定义也可以获取
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encod));
//从流的当前位置读取到末尾
strResult = sr.ReadToEnd();
sr.Close();
response.Close();
newStream.Close();

}
catch (Exception exp)
{

strResult = "错误:" + exp.Message;

}
}




原标题:本地测试IIS,Post调用接口

关键词:IIS

IIS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

4月1日起生效!eBay英国站费用变更详情!:https://www.kjdsnews.com/a/1376782.html
汉王科技2022年净亏损1.36亿元,同比下降350.63%:https://www.kjdsnews.com/a/1376783.html
这是一篇能够教会你运营阿里巴巴国际站的文章:https://www.kjdsnews.com/a/1376784.html
亚马逊广告效果如何提升?Amazon广告投放效果最大化攻略:https://www.kjdsnews.com/a/1376785.html
斋月shopee选品分析:https://www.kjdsnews.com/a/1376786.html
5个跨境AI工具盘点,独立站高效运营必备!:https://www.kjdsnews.com/a/1376787.html
TikTok斥资210万美元游说美国参议院阻止法案通过 :https://www.kjdsnews.com/a/1836653.html
TikTok斥资210万美元游说美国参议院阻止法案通过 :https://www.goluckyvip.com/news/188220.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流