Error al hacer un Post WebRequest
Al hacer una peticion mediante WebRequest me esta generando el error "The remote server returned an error: (401) Unauthorized."
Como comentario hago el mismo request desde Soap UI y ahi no tengo problema, no se si sea algun problema en mi codigo ojala me puedan ayudar, anexo codigo ejecutado
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
ServicePointManager.Expect100Continue = true;
ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => true;
X509Certificate2Collection certificates = new X509Certificate2Collection();
certificates.Import(_certificatePath, _certificatePass, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(requestUri);
req.AllowAutoRedirect = true;
req.ClientCertificates = certificates;
req.Method = method.Method;
string tString = JsonConvert.SerializeObject(body);
byte[] data = UTF8Encoding.UTF8.GetBytes(tString);
req.ContentLength = data.Length;
req.ContentType = "application/json; charset=utf-8";
req.GetRequestStream().Write(data, 0, data.Length);
req.Headers.Add("Authorization", "bearer " + token);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();