POST URL 地址数据打开URL地址

如下为.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)

        {

            

        }

posted @ 2024-10-17 10:50  皑上雪  阅读(6)  评论(0编辑  收藏  举报