IP、Port表示地址及端口,可配置或写死
public string PostDate(string IP,string Port)
{
//设置参数
string content= "{\"userName\":\"" 0000 "\"" +
",\"password\":\"123456\"}";
//填充路径
string strUrl = string.Format("http://{0}:{1}/api/cdss/sys/doctor/login", IP, Port);
var uri = new Uri(strUrl);
//post
//创建路径
HttpWebRequest httpWeb = (HttpWebRequest)WebRequest.Create(uri);
//httpWeb.Headers.Add("Accept", "application/json");//添加消息头
httpWeb.Timeout = 20000;
httpWeb.Method = "POST";
httpWeb.ContentType = "application/json; charset=utf-8";
byte[] bytePara = Encoding.UTF8.GetBytes(content);
using (Stream reqStream = httpWeb.GetRequestStream())
{
//提交数据
reqStream.Write(bytePara, 0, bytePara.Length);
}
//获取服务器返回值
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWeb.GetResponse();
Stream stream = httpWebResponse.GetResponseStream();
StreamReader streamReader = new StreamReader(stream, Encoding.GetEncoding("utf-8"));
//获得返回值
string result = streamReader.ReadToEnd();
stream.Close();
return result;
}
成功获取Token后根据Token传参并打开网页
public void LoadPage()
{
//根据实际情况填充IP及Port
string IP="";
string Port="";
string result=PostDate(IP,Port);
//反序列化JSON
JObject jo = (JObject)JsonConvert.DeserializeObject(result);
//得到Token值
//示例JSON:{ "code": 200, "msg": "请求成功", "data": {"access_token": "token内容" } }
string token = jo["data"]["access_token"].ToString();
//创建调用外部程序
Process pro = new Process();
string url = string.Format("http://{4}:{5}/cdss/new-home?access_token={0}&patientId={1}&patientNo={2}&deptId={3}", token, "12345", 1, "3501", IP, Port);
//打开地址
Process.Start(url);
文章来源:https://www.toymoban.com/news/detail-403659.html
}文章来源地址https://www.toymoban.com/news/detail-403659.html
到了这里,关于C#使用post方式调用接口获取Token及调用网页地址的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!