I am trying to do a POST request with data, however I get an Exception about the project could not create a secure channel SSL or TSL, when the function request.GetRequestStream()
is reached.
This is the function that I use:
public bool PreRegister()
{
try
{
string url = "https://paytest.megasoft.com.ve/payment/action/v2-preregistro";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Headers.Add("Authorization: Basic " + Crypt.Base64_Encode("grupototal99:Grupo01."));
request.Method = "POST";
request.ContentType = "application/xml";
request.Accept = "application/xml";
XElement requestXML =
new XElement("request", new XElement("cod_afiliacion", 1911202001));
byte[] bytes = Encoding.UTF8.GetBytes(requestXML.ToString());
request.ContentLength = bytes.Length;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
using (Stream putStream = request.GetRequestStream())
{
putStream.Write(bytes, 0, bytes.Length);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
StreamReader rdr = new StreamReader(resStream);
code = rdr.ReadToEnd();
return true;
}
catch(Exception ex)
{
return false;
}
}