/// <summary> /// 查询接口(返回字符串) /// </summary> /// <param name="jsonurl">查询地址</param> /// <param name="querystr">查询字符串</param> /// <param name="responsejson">返回数据</param> /// <param name="errmsg">错误信息</param> /// <returns></returns> public static bool QueryJson(string jsonurl, string querystr, out string responsejson, out string errmsg) { #region ServerXMLHTTP xmlhttp = new ServerXMLHTTP(); errmsg = ""; responsejson = ""; try { xmlhttp.open("POST", jsonurl, false, null, null); //xmlhttp.setRequestHeader("Content-Type", "text/xml;charset=utf-8"); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlhttp.send(querystr); if (xmlhttp.readyState == 4) { if (xmlhttp.responseText.Trim() != "") { responsejson = xmlhttp.responseText; } else { responsejson = ""; errmsg = "ErrEmpty"; } } } catch { errmsg = "ErrConnect"; } finally { xmlhttp.abort(); } if (errmsg != "") { Tools.SendeMail("", "*****@*****.**", "hbe json error", errmsg, true, Encoding.UTF8); return(false); } else { return(true); } #endregion }
public static string GetSinaValue(string url, string sendData) { ServerXMLHTTP xmlhttp = new ServerXMLHTTP(); string errmsg = ""; string responsejson = ""; string jsonurl = url; try { xmlhttp.open("POST", jsonurl, false, null, null); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlhttp.send(sendData); if (xmlhttp.readyState == 4) { if (xmlhttp.responseText.Trim() != "") { responsejson = xmlhttp.responseText; } else { responsejson = ""; errmsg = "ErrEmpty"; } } } catch { errmsg = "ErrConnect"; } finally { xmlhttp.abort(); } if (errmsg != "") { return(errmsg); } else { return(responsejson); } }