如下为.net版调用实例,关键是两点:1、Post方式;2、参数以JSON格式:
string postUrl = "https://xxx.com/caradigm";
string paramData =
"{\"ex_patientid\":\"10_2000_XXXXXXX\",\"userName\":\"3000419\",\"ex_appid\":\"XXXXXXX\"}";
try
{
byte[] byteArray = Encoding.UTF8.GetBytes(paramData); //转化
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
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();
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
ret = sr.ReadToEnd();
sr.Close();
response.Close();
newStream.Close();
return ret ; //ret即为URL的地址。
}
catch (Exception ex)
{
}
标签:byteArray,URL,地址,newStream,Close,POST,webReq From: https://www.cnblogs.com/songconglai/p/18471567