Example #1
0
        public static string HttpPost(string uri, object data, SerializationType serializationType)
        {
            HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;

            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
            string xmlStr = string.Empty;

            if (data is string)
            {
                xmlStr = (string)data;
            }
            else if (serializationType == SerializationType.Xml)
            {
                xmlStr = SerializationHelper.XmlSerialize(data);
                SerializationHelper.XmlDeserialize(data.GetType(), xmlStr);
            }
            else if (serializationType == SerializationType.Json)
            {
                xmlStr = SerializationHelper.JsonSerialize(data);
            }
            byte[] bytes = new CNNWebClient {
                Timeout = 300
            }.UploadData(uri, "POST", Encoding.UTF8.GetBytes(xmlStr));
            return(Encoding.UTF8.GetString(bytes));
        }
        /// <summary>
        /// 向远程Url Post数据
        /// </summary>
        /// <param name="uri">请求URL地址</param>
        /// <param name="data">请求参数</param>
        /// <param name="serializationType">参数序列化方式</param>
        /// <returns>响应字符串</returns>
        public static string HttpPost(string uri, object data, SerializationType serializationType)
        {
            HttpWebRequest _request = HttpWebRequest.Create(uri) as HttpWebRequest;

            _request.Method      = "POST";
            _request.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
            string _requestParamter = string.Empty;

            if (data is string)
            {
                _requestParamter = (string)data;
            }
            else
            {
                if (serializationType == SerializationType.Xml)
                {
                    _requestParamter = SerializeHelper.XmlSerialize(data);
                }
                else if (serializationType == SerializationType.Json)
                {
                    _requestParamter = SerializeHelper.JsonSerialize(data);
                }
            }

            CNNWebClient _webClient = new CNNWebClient();

            _webClient.Timeout = 300;
            byte[] _responeBuffer = _webClient.UploadData(uri, "POST", Encoding.UTF8.GetBytes(_requestParamter));
            return(Encoding.UTF8.GetString(_responeBuffer));
        }
Example #3
0
 public static string HttpPost(string uri, NameValueCollection data)
 {
     byte[] bytes = new CNNWebClient {
         Encoding = Encoding.UTF8, Timeout = 300
     }.UploadValues(uri, "POST", data);
     return(Encoding.UTF8.GetString(bytes));
 }
        /// <summary>
        /// 向远程Url Post数据
        /// </summary>
        /// <param name="uri">请求URL地址</param>
        /// <param name="data">请求参数</param>
        /// <returns>响应字符串</returns>
        public static string HttpPost(string uri, NameValueCollection data)
        {
            CNNWebClient _webClient = new CNNWebClient();

            _webClient.Encoding = Encoding.UTF8;
            _webClient.Timeout  = 300;
            byte[] _responeBuffer = _webClient.UploadValues(uri, "POST", data);
            return(Encoding.UTF8.GetString(_responeBuffer));
        }
Example #5
0
        public static string HttpPost(string uri, System.Collections.Specialized.NameValueCollection data)
        {
            CNNWebClient wc = new CNNWebClient();

            wc.Encoding = Encoding.UTF8;
            wc.Timeout  = 300;
            var    t     = wc.UploadValues(uri, "POST", data);
            string tText = Encoding.UTF8.GetString(t);

            return(tText);
        }
Example #6
0
        public static string HttpPost(string uri, object data, SerializationType serializationType)
        {
            HttpWebRequest request = HttpWebRequest.Create(uri) as HttpWebRequest;

            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded;charset=utf-8";

            string dataStr = string.Empty;

            if (data is string)
            {
                dataStr = (string)data;
            }
            else
            {
                if (serializationType == SerializationType.Xml)
                {
                    dataStr = SerializationHelper.XmlSerialize(data);
                    object o = SerializationHelper.XmlDeserialize(data.GetType(), dataStr);
                }
                else if (serializationType == SerializationType.Json)
                {
                    dataStr = SerializationHelper.JsonSerialize(data);
                }
            }
            CNNWebClient wc = new CNNWebClient();

            wc.Timeout = 300;
            var    t     = wc.UploadData(uri, "POST", Encoding.UTF8.GetBytes(dataStr));
            string tText = Encoding.UTF8.GetString(t);

            /*
             * System.Diagnostics.Debug.WriteLine(tText);
             * byte[] buffer;
             * Stream stream;
             * if (!string.IsNullOrWhiteSpace(dataStr))
             * {
             *  buffer = Encoding.UTF8.GetBytes(dataStr);
             *  stream = request.GetRequestStream();
             *  stream.Write(buffer, 0, buffer.Length);
             * }
             * //request.d
             * HttpWebResponse response = request.GetResponse() as HttpWebResponse;
             *
             * stream = response.GetResponseStream();
             * buffer = new byte[response.ContentLength];
             * stream.Read(buffer, 0, (int)response.ContentLength);
             * //string encoding = string.IsNullOrWhiteSpace(response.ContentEncoding) ? "uft-8" : response.ContentEncoding;
             * string responseText = Encoding.UTF8.GetString(buffer);
             * System.Diagnostics.Debug.WriteLine(responseText);
             * return responseText;
             */
            return(tText);
        }
Example #7
0
 Byte[] GetRomoteByte(string path)
 {
     try
     {
         CNNWebClient client = new CNNWebClient();
         client.Timeout = 5;
         return(client.DownloadData(path));
     }
     catch
     {
         errorString = "加载图片失败 =.=,没福利了";
     }
     return(null);
 }
Example #8
0
 string GetRomoteString(string path)
 {
     try
     {
         CNNWebClient client = new CNNWebClient();
         client.Timeout = 5;
         return(client.DownloadString(path));
     }
     catch
     {
         errorString = "图片地址加载失败 =.=,没福利了";
     }
     return(null);
 }
        /// <summary>
        /// 向远程Url Post数据
        /// </summary>
        /// <param name="url">url</param>
        /// <param name="postData">post数据</param>
        /// <param name="header">Header数据</param>
        /// <param name="serializationType">post数据以及返回数据序列号处理方式</param>
        /// <returns>返回数据</returns>
        public static string Post(string url, object postData, NameValueCollection header, SerializationType serializationType)
        {
            string _serializaPostDataString = SerializePostDataObject(postData, serializationType);

            using (CNNWebClient _webClient = new CNNWebClient())
            {
                _webClient.Timeout = 300;
                if (header != null)
                {
                    _webClient.Headers.Add(header);
                }

                byte[] _responseBuffer = _webClient.UploadData(url, "POST", Encoding.UTF8.GetBytes(_serializaPostDataString));

                return(_responseBuffer != null?Encoding.UTF8.GetString(_responseBuffer) : string.Empty);
            }
        }
Example #10
0
        public string GetClientSlidePath(string url)
        {
            string str = "";

            try
            {
                //string url = DNTRequest.GetString("url");
                CNNWebClient _WebClient = new CNNWebClient();
                //_WebClient.Timeout = 1;
                _WebClient.Encoding = System.Text.Encoding.UTF8;//定义对象语言

                str = _WebClient.DownloadString(url);
                return(str);
            }
            catch
            {
                return("-1");
            }
        }
Example #11
0
        //获取单支股票行情
        private void stockmarket_one(string stock, ref string stockdata)
        {
            string stockurl = "";

            CNNWebClient webClient = new CNNWebClient();    //通过WebClient方式去获取资源文件

            stock_appendurl(stock, ref stockurl, CfgStruct.marketlist_t, false);
            Uri uri = new Uri(stockurl, false);

            try
            {
                stockdata = webClient.DownloadString(uri);
            }
            catch (InvalidCastException e)
            {
                throw (e);
            }

            webClient.Dispose();
        }
Example #12
0
        //获取单支股票行情
        private void stockmarket_one(string stock, ref string stockdata)
        {
            string stockurl = "";

            CNNWebClient webClient = new CNNWebClient();    //通过WebClient方式去获取资源文件
            stock_appendurl(stock, ref stockurl, CfgStruct.marketlist_t,false);
            Uri uri = new Uri(stockurl, false);
            try
            {
                stockdata = webClient.DownloadString(uri);
            }
            catch(InvalidCastException e)
            {
                throw (e);
            }

            webClient.Dispose();
        }