平台接口C#调用示例

平台接口POST请求

C#调用示例
using System;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string service = "PT_PACS_V_PACS_EMRINFO";
            string Url = "http://10.0.1.212:9526/hai/HttpEntry/";
            string urid = "portal_cyhk_pacs";
            string pwd = "cyhkTopacs123";
            string parameter = "";
            try
            {
                Dictionary<string, string> myDict = new Dictionary<string, string>();
                myDict.Add("service", service);
                myDict.Add("urid", urid);
                myDict.Add("pwd", pwd);
                myDict.Add("parameter", parameter);

                string result = string.Empty;

                FormUrlEncodedContent httpContent = new FormUrlEncodedContent(myDict);

                using (HttpClient httpClient = new HttpClient())
                {
                    HttpResponseMessage response = httpClient.PostAsync(Url, httpContent).Result;
                    string statusCode = response.StatusCode.ToString();
                    if (response.IsSuccessStatusCode)
                    {
                        result = response.Content.ReadAsStringAsync().Result;
                    }
                }
                Console.WriteLine(result);
            }
            catch (HttpRequestException e)
            {
                throw new Exception(e.Message);
            }
        }

    }
}

已有 0 条评论

    欢迎您,新朋友,感谢参与互动!