Ejemplo n.º 1
0
        //钉钉Api请求
        public static string ApiFun(string Type, string strURL, string paramsStr)
        {
            try
            {
                if (Type == "GET")
                {
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL);

                    //GET请求
                    request.Method           = Type;
                    request.ReadWriteTimeout = 10000;
                    request.ContentType      = "application/json";
                    //request.Headers.Add("ID", "10227");
                    HttpWebResponse response         = (HttpWebResponse)request.GetResponse();
                    Stream          myResponseStream = response.GetResponseStream();
                    StreamReader    myStreamReader   = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));

                    //返回内容
                    string retString = myStreamReader.ReadToEnd();
                    return(retString);
                }
                else
                {
                    WebClientUtils w = new WebClientUtils(30 * 1000);
                    byte[]         postData;
                    byte[]         byRemoteInfo;
                    string         rtn = "";
                    w.Headers.Add("Content-Type", "application/json");
                    //w.Headers.Add("ID", "10227");
                    postData     = Encoding.UTF8.GetBytes(paramsStr);
                    byRemoteInfo = w.UploadData(strURL, "POST", postData);
                    rtn          = System.Text.Encoding.UTF8.GetString(byRemoteInfo);
                    return(rtn);
                }
            }
            catch (Exception ex)
            {
                TxtLog("Log", "接口请求失败:" + ex.ToString());
                return("");
            }
        }
Ejemplo n.º 2
0
        public static string httpPostFun(string strURL, string path, string paramsStr)
        {
            WebClientUtils w = new WebClientUtils(30 * 1000);

            byte[] postData;
            byte[] byRemoteInfo;
            string rtn = "";

            try
            {
                w.Headers.Add("Content-Type", "application/json");
                postData     = Encoding.UTF8.GetBytes(paramsStr);
                byRemoteInfo = w.UploadData(strURL, "POST", postData);
                rtn          = System.Text.Encoding.UTF8.GetString(byRemoteInfo);
                return(rtn);
            }
            catch (Exception ex)
            {
                TxtLog("Log", "接口请求失败:" + ex.ToString());
                return("");
            }
        }