数据POST操作
程序员文章站
2022-03-20 21:18:04
WXUserPara wxpara = new WXUserPara(); wxpara.userid = o.LoginName;//成员ID对应客户端账号 wxpara.name = o.Name;//成员名称 wxpara.mobile = o.MobilePin;//手机号码 ... ......
WXUserPara wxpara = new WXUserPara(); wxpara.userid = o.LoginName;//成员ID对应客户端账号 wxpara.name = o.Name;//成员名称 wxpara.mobile = o.MobilePin;//手机号码 wxpara.department = (int)EOQuestionLogic.GetWxGetList(o.DefaultDepartmentID).Tables[0].Rows[0]["wx_department_id"]; wxpara.order = (int)o.OrderNum;//排序 wxpara.gender = 1;//性别默认男 wxpara.email = o.Email;//邮箱 /*业务系统人员配置增加职务,*/ if (!string.IsNullOrEmpty(txtDuty.Text)) { wxpara.position = txtDuty.Text; } string json = JsonConvert.SerializeObject(wxpara); //调用webAPI接口,post数据到企业微信中 string ss = HttpPost("http://XXX/eo/wxapi/api/EO/updateUser", json); public static string HttpPost(string url, string body) { Encoding encoding = Encoding.UTF8; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.Accept = "text/html, application/xhtml+xml, */*"; request.ContentType = "application/json"; byte[] buffer = encoding.GetBytes(body); request.ContentLength = buffer.Length; request.GetRequestStream().Write(buffer, 0, buffer.Length); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { return reader.ReadToEnd(); } } public class WXUserPara { /// <summary> /// 成员UserID /// </summary> public string userid { get; set; } /// <summary> /// 成员名称 /// </summary> public string name { get; set; } /// <summary> /// 英文名 /// </summary> public string english_name { get; set; } /// <summary> /// 手机号码 /// </summary> public string mobile { get; set; } /// <summary> /// 微信部门ID /// </summary> public int department { get; set; } /// <summary> /// 排序 /// </summary> public int order { get; set; } /// <summary> /// 职位信息 /// </summary> public string position { get; set; } /// <summary> /// 性别 /// </summary> public int gender { get; set; } /// <summary> /// 邮箱 /// </summary> public string email { get; set; } /// <summary> /// 座机 /// </summary> public string telephone { get; set; } /// <summary> /// 上级字段 /// </summary> public string isleader { get; set; } /// <summary> /// 成员头像的mediaid /// </summary> public string avatar_mediaid { get; set; } /// <summary> /// 启用 /// </summary> public int enable { get; set; } /// <summary> /// 自定义字段 /// </summary> public string extattr { get; set; } /// <summary> /// 成员对外属性 /// </summary> public string ternal_profile { get; set; } }
推荐阅读