Esempio n. 1
0
        /// <summary>
        /// Base64解码 </summary>
        /// <param name="base64str"> 待处理的Base64编码的字符串 </param>
        /// <returns> 解码后的字符串 </returns>
        public static string ozBase64ToStr(string base64str)
        {
            string base64Codep;

            try
            {
                base64Codep = StringHelperClass.NewString(AnalysysEncoder.decode(base64str));
                return(base64Codep);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 发送消息至接收服务器 </summary>
        /// <returns> HttpResponse </returns>
        public virtual string send()
        {
            HttpClient          httpclient = new HttpClient();
            HttpResponseMessage response   = null;

            try
            {
                httpclient.DefaultRequestHeaders.Add("User-Agent", "Analysys Java SDK");
                if (this.egHeaderParams != null)
                {
                    foreach (KeyValuePair <string, string> entry in this.egHeaderParams.SetOfKeyValuePairs())
                    {
                        httpclient.DefaultRequestHeaders.Add(entry.Key, entry.Value);
                    }
                }
                HttpContent egRequest = null;
                if (isEncode.Value)
                {
                    egRequest = new StringContent(AnalysysEncoder.encode(AnalysysEncoder.compress(jsonData)));
                }
                else
                {
                    egRequest = new StringContent(jsonData);
                    egRequest.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                }
                response = httpclient.PostAsync(this.serverUrl, egRequest).Result;
                string message = response.Content.ReadAsStringAsync().Result;
                //try
                //{
                //    message = AnalysysEncoder.uncompress(AnalysysEncoder.decode(message));
                //}
                //catch (Exception e)
                //{
                //    throw e;
                //}
                //printLog(message, jsonData);
                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    if (!string.ReferenceEquals(message, null) && message.Contains("\"code\":200"))
                    {
                        return(message);
                    }
                    else
                    {
                        throw new AnalysysException(message);
                    }
                }
                else
                {
                    throw new AnalysysException(message);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (response != null)
                {
                    response.Dispose();
                }
                if (httpclient != null)
                {
                    httpclient.Dispose();
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Base64编码 </summary>
        /// <param name="str"> 待处理字符串 </param>
        /// <returns> 编码后的字符串 </returns>
        public static string ozStrToBase64(string str)
        {
            string basestr = AnalysysEncoder.encode(str.GetBytes());

            return(basestr);
        }