get方式调用腾讯企业邮接口并接受返回参数

it2022-05-05  145

/// 获取腾讯企业邮部门列表 // < /summary> /// < param name="token">调用接口凭证</param> /// < param name="id">部门id。获取指定部门及其下的子部门。id为1时可获取根部门下的子部门。< /param> public static string SelectAllDepartmentAction(string token, string id) { //string str1 = "../"; //var Access_token = GetAccessTokenByUrlAndSave2File(str1); string url = " https://api.exmail.qq.com/cgi-bin/department/list?access_token=" + token + "&id=" + id; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; request.ContentType = "application/json;charset=UTF-8"; HttpWebResponse response = (HttpWebResponse) request.GetResponse(); string dataStr = GetResponseString(response); return dataStr; } /// < summary> /// 获取请求的数据 /// < /summary> public static string GetResponseString(HttpWebResponse webresponse) { using (Stream s = webresponse.GetResponseStream()) { StreamReader reader = new StreamReader(s, Encoding.UTF8); return reader.ReadToEnd(); } } /// <summary> /// POST,返回LitJson.JsonData对象 /// </summary> /// <param name="pdata"></param> /// <param name="responseString"></param> /// <returns></returns> private static LitJson.JsonData PostJson(PostData pdata, out string responseString) { responseString = String.Empty; try { Encoding encoding = Encoding.GetEncoding(pdata.encoding); byte[] data = encoding.GetBytes(pdata.contentData); HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(pdata.url); webReq.Method = "POST"; webReq.ContentLength = data.Length; webReq.ContentType = pdata.contentType + "; charset=" + pdata.encoding; if (!String.IsNullOrEmpty(pdata.header)) { webReq.Headers.Add(pdata.header); } Stream webStream = webReq.GetRequestStream(); webStream.Write(data, 0, data.Length); WebResponse webResp = webReq.GetResponse(); Stream webRespStream = webResp.GetResponseStream(); StreamReader reader = new StreamReader(webRespStream, encoding); string respXml = reader.ReadToEnd(); reader.Close(); reader.Dispose(); webResp.Close(); responseString = respXml; return LitJson.JsonMapper.ToObject(respXml); ; } catch (Exception ex) { responseString = ex.ToString(); return null; } finally { writeLog(string.Format("PostData:{0}====PostUrl:{1}====response:{2}", pdata.contentData, pdata.url, responseString)); } }

前端调用接口

function AddZKLXFS() { if (!checkMobile($("#txtTePhoneNum2").val())) { $.messager.alert("提示", "请输入正确的手机号"); return; } if (!checkEmail($("#txtTeEmail2").val())) { $.messager.alert("提示", "请输入正确的邮箱"); return; } $.ajax({ type: "post", url: '../../Handler/CommonHandler.ashx?action=GetComm&Method=ApiService.T_Tenants.AddContact&EType=Soa', data: { "zkID": zkID, "txtTePhoneNum2": $("#txtTePhoneNum2").val(), "txtTeTel_Home2": $("#txtTeTel_Home2").val(), "txtTeTel_Company2": $("#txtTeTel_Company2").val(), "txtWeChat2": $("#txtWeChat2").val(), "txtTeEmail2": $("#txtTeEmail2").val() }, dataType: "json", success: function (data) { if (data.State) { $('#add_zklx').dialog('close'); } else { $.messager.alert('提示', '操作失败,' + data.Msg, 'error'); } } }); }

最新回复(0)