Beispiel #1
0
        public override HttpWebRequest CreateRequest(Uri serviceUri, HttpParameterCollection parameters)
        {
            UriBuilder    uriBuilder         = new UriBuilder(serviceUri);
            StringBuilder paramStringBuilder = new StringBuilder();
            string        key = null;

            if (parameters != null)
            {
                for (int i = 0; i < parameters.Count; i++)
                {
                    key = parameters[i].Name;
                    paramStringBuilder.AppendFormat("{0}={1}", HttpUtility.UrlEncode(key), HttpUtility.UrlEncode(parameters[i].Value));
                    if (i < (parameters.Count - 1))
                    {
                        paramStringBuilder.Append("&");
                    }
                }
            }
            uriBuilder.Query = paramStringBuilder.ToString();
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uriBuilder.Uri);

            request.Method      = base.HttpVerb;
            request.ContentType = base.BodyEncoder.ContentType;
            this.commandText    = uriBuilder.Uri.AbsoluteUri;
            return(request);
        }
 public void Add(HttpParameterCollection parameters)
 {
     foreach (HttpParameter parameter in parameters)
     {
         base.Add(parameter);
     }
 }
        public sealed override void WriteRequestBody(Stream stream, HttpClient client, Encoding characterEncoding)
        {
            HttpParameterCollection  parameters      = client.Parameters;
            HttpDataSourceCollection dataItems       = client.Data;
            StringBuilder            postBodyBuilder = new StringBuilder();

            byte[] footerBytes = characterEncoding.GetBytes("\r\n--" + this.Boundary + "--\r\n");
            if ((parameters != null) && (parameters.Count > 0))
            {
                foreach (HttpParameter parameter in parameters)
                {
                    AppendRestParameter(postBodyBuilder, parameter, this.Boundary);
                }
                byte[] parameterBytes = characterEncoding.GetBytes(postBodyBuilder.ToString());
                stream.Write(parameterBytes, 0, parameterBytes.Length);
            }
            if ((dataItems != null) && (dataItems.Count > 0))
            {
                foreach (HttpDataSource dataItem in dataItems)
                {
                    AppendDataItem(stream, dataItem, this.Boundary, characterEncoding);
                }
            }
            stream.Write(footerBytes, 0, footerBytes.Length);
        }
Beispiel #4
0
        public sealed override void WriteRequestBody(Stream stream, HttpClient client, Encoding characterEncoding)
        {
            HttpParameterCollection parameters = client.Parameters;

            if ((parameters != null) && (parameters.Count > 0))
            {
                byte[]        newlineBytes = characterEncoding.GetBytes("\r\n");
                HttpParameter parameter    = null;
                for (int i = 0; i < parameters.Count; i++)
                {
                    parameter = parameters[i];
                    string parameterString = string.Format("{0}={1}{2}", HttpUtility.UrlPathEncode(parameter.Name), HttpUtility.UrlPathEncode(parameter.Value), (i < (parameters.Count - 1)) ? "&" : string.Empty);
                    byte[] parameterBytes  = characterEncoding.GetBytes(parameterString);
                    stream.Write(parameterBytes, 0, parameterBytes.Length);
                }
                stream.Write(newlineBytes, 0, newlineBytes.Length);
            }
        }
Beispiel #5
0
 public virtual HttpWebRequest CreateRequest(Uri serviceUri, HttpParameterCollection parameters)
 {
     return((HttpWebRequest)WebRequest.Create(serviceUri));
 }