/// <summary>
 /// Writes the POST parameters to the request stream.
 /// </summary>
 /// <param name="request">The request to write the parameters to.</param>
 /// <param name="parameters">The set of key/value pairs to write as parameters.</param>
 public static void WriteParameters(this HttpWebRequest request, Dictionary<string, string> parameters)
 {
     string data = parameters.ToHttpVariables();
     byte[] dataStream = Encoding.UTF8.GetBytes(data);
     request.ContentLength = dataStream.Length;
     using (Stream stream = request.GetRequestStream())
     {
         stream.Write(dataStream, 0, dataStream.Length);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Creates a URL with QueryString parameters.
        /// </summary>
        /// <param name="urlbase">The base URL.</param>
        /// <param name="queryParams">A dictionary of QueryString parameters.</param>
        /// <returns>A URL with QueryString parameters.</returns>
        public string Create(string urlbase, Dictionary<string, string> queryParams)
        {
            urlbase = urlbase ?? string.Empty;
            if (queryParams == null || queryParams.Count == 0)
            {
                return urlbase;
            }

            string queryString = queryParams.ToHttpVariables();
            string join = (urlbase.IndexOf(QueryString.StartOf, StringComparison.Ordinal) == -1) ? QueryString.StartOf : QueryString.VariableDelimiter;
            return string.Format("{0}{1}{2}", urlbase, join, queryString);
        }