public HttpWebRequest Create()
{
var request = (HttpWebRequest) WebRequest.Create(_requestUri);
if (_certificates.Any())
{
foreach (var x509Certificate in _certificates)
{
request.ClientCertificates.Add(x509Certificate);
}
}
if (_headers.Any())
{
foreach (var header in _headers)
{
request.Headers.Add(header.Key, header.Value);
}
}
request.Method = _method;
request.ContentType = _contentType;
request.Accept = _accept ?? "application/xml";
request.ContentLength = 0;
if (!string.IsNullOrEmpty(_body))
{
byte[] bytes = Encoding.UTF8.GetBytes(_body);
request.ContentLength = bytes.Length;
using (Stream stream = request.GetRequestStream())
{
stream.Write(bytes, 0, bytes.Length);
}
}
return request;
}