ChobiQ.DoubanFMAPICodePack.FormData.GetFormString C# (CSharp) Method

GetFormString() public method

public GetFormString ( ) : string
return string
        public virtual string GetFormString()
        {
            Type t = this.GetType();
            var props = t.GetProperties();

            string s = String.Empty;

            for (int i = 0; i < props.Length; i++)
            {
                var prop = props[i];

                var value = prop.GetValue(this, new Object[] { });

                if (value != null)
                    s += String.Format("{0}={1}{2}",
                        prop.Name, value,
                        (i == props.Length - 1 ? String.Empty : "&"));
            }

            return s;
        }

Usage Example

Example #1
0
        public static Stream GetPostResponseStream(string requestUri,
                                                   FormData data)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
                "https://www.douban.com" + requestUri);

            request.Method          = "POST";
            request.ProtocolVersion = HttpVersion.Version11;

            request.Headers.Add("Origin", "onering://radio");
            request.UserAgent = "Mozilla/5.0 (Windows NT 6.1) "
                                + "AppleWebKit/535.19 "
                                + "(KHTML, like Gecko) Chrome/18.0.1025.151 Safari/535.19";

            request.ContentType = "application/x-www-form-urlencoded";
            request.Accept      = "application/json, text/javascript, */*; q=0.01";
            request.KeepAlive   = true;

            request.CookieContainer = s_cookies;

            using (StreamWriter writer = new StreamWriter(
                       request.GetRequestStream()))
            {
                writer.Write(data.GetFormString());
                writer.Close();
            }

            return(request.GetResponse().GetResponseStream());
        }
All Usage Examples Of ChobiQ.DoubanFMAPICodePack.FormData::GetFormString