コード例 #1
0
        public bool PostData(string url, Dictionary <string, object> param = null, bool isJson = false)
        {
            var result = false;

            while (true)
            {
                if (string.IsNullOrEmpty(url))
                {
                    break;
                }

                try {
                    // init
                    var request = WebRequest.Create(url);
                    request.Method = "POST";

                    // param
                    string options = null;
                    if (isJson)
                    {
                        options = JsonConvert.SerializeObject(param);
                    }
                    else
                    {
                        options             = THelper.Dict2QueryString(param);
                        request.ContentType = "application/x-www-form-urlencoded";
                    }
                    byte[] data = Encoding.UTF8.GetBytes(options);
                    request.ContentLength = data.Length;

                    // request
                    Stream streamWriter = request.GetRequestStream();
                    streamWriter.Write(data, 0, data.Length);

                    // response
                    m_stream = request.GetResponse().GetResponseStream();
                    result   = true;
                }
                catch { }

                break;
            }
            return(result);
        }
コード例 #2
0
        public bool GetData(string url, Dictionary <string, object> param = null)
        {
            var result = false;

            while (true)
            {
                if (string.IsNullOrEmpty(url))
                {
                    break;
                }

                try {
                    url += THelper.Dict2QueryString(param);
                    var request = WebRequest.Create(url);
                    request.Method = "GET";
                    m_stream       = request.GetResponse().GetResponseStream();
                    result         = true;
                }
                catch { }

                break;
            }
            return(result);
        }