HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
string param = BuildParamGetPatientInfoForSDEY(inHospitalID, caseNum);
logInfo.LogStepDetail(cCfg, "请求的JSON内容:", param);
Encoding encoding = Encoding.UTF8;
byte[] byteArray = Encoding.UTF8.GetBytes(param);
req.Method = "POST";
req.Headers.Add("access_token", token);
req.ContentType = "application/json";
req.ContentLength = byteArray.Length;
req.Accept = "*/*";
req.Timeout = 30 * 1000;
req.ReadWriteTimeout = 30 * 1000;
req.ServicePoint.Expect100Continue = false;
using (Stream reqStream = req.GetRequestStream())
{
reqStream.Write(byteArray, 0, byteArray.Length);
}
using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
{
responseDate = reader.ReadToEnd();
logInfo.LogStepDetail(cCfg, "POST请求的返回结果", responseDate);
}
}
利用HttpWebRequest发送HTTP请求
最新推荐文章于 2022-02-14 17:20:19 发布