Beispiel #1
0
 /// <summary>
 /// Specifies the payload to use with the request. Automatically overrides the ContentSize property.
 /// </summary>
 /// <param name="payload">The payload value.</param>
 /// <param name="requestEncoding">The value to encode the payload.</param>
 /// <returns>Itself.</returns>
 public Http SetPayload(string payload, Encoding requestEncoding)
 {
     byte[] data = !string.IsNullOrEmpty(payload) ? requestEncoding.GetBytes(payload) : requestEncoding.GetBytes(String.Empty);
     WebReq.ContentLength = data.Length;
     if (WebReq.ContentLength > 0)
     {
         using (var dataStream = WebReq.GetRequestStream())
             dataStream.Write(data, 0, data.Length);
     }
     return(this);
 }