public string Post(string PostUrl, string Parameters)
{
string content = string.Empty;
try
{
byte[] bytesRequestData = Encoding.UTF8.GetBytes(Parameters.ToString());
HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(PostUrl);
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Ssl3;
myReq.Method = "post";
myReq.ContentType = "text/xml; charset=utf-8";
myReq.Headers.Add("Authorization", "Basic " + GetEncodedCredentials());
myReq.ContentLength = bytesRequestData.Length;
Stream requestStream = myReq.GetRequestStream();
requestStream.Write(bytesRequestData, 0, bytesRequestData.Length);
requestStream.Close();
HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
Stream myStream = HttpWResp.GetResponseStream();
StreamReader reader = new StreamReader(myStream, Encoding.UTF8);
content = reader.ReadToEnd();
reader.Close();
HttpWResp.Close();
}
catch (Exception ex)
{
content = ex.ToString();
}
return content;
}
private bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
}
|