首页 >> 中医新闻

ASPNetPost方式获取数据流的一种

中医新闻  2020年08月07日  浏览:2 次

Post方式获取数据流的一种简单写法

最近在弄一些第三方的平台,经常调用第三方的接口实现某些特定的功能

在实现的同时基本上都需要本地的数据经过服务器在Request到第三方的服务器中处理,再返回相应的数据结构体:json/xml

以下是我总结的一个小方法,请农友们笑纳:

public static string PostWebReq(string PostUrl, string ParamData, Encoding DataEncode)

string ret = pty;

byte[] byteArray = tBytes(ParamData);

HttpWebRequest webReq = (HttpWebRequest)eate(new Uri(PostUrl));

thod = "POST";

ntentType = "application/x-www-form-urlencoded";

ntentLength = ngth;

Stream newStream = tRequestStream();

ite(byteArray, 0, ngth);

ose();

HttpWebResponse response = (HttpWebResponse)tResponse();

StreamReader sr = new StreamReader(tResponseStream(), DataEncode);

ret = adToEnd();

ose();

ose();

ose();

catch (WebException ex)

iteLog(ror, ssage);

finally

iteLog(, ret);

return ret;

引起腹胀的原因有哪些
南昌白癜风治疗中心
南通专治白癜风的医院
友情链接