private const int _timeOut = 15000;
public static int TimeOut = 120000;
public static int TimeOutReadWrite = 15000;
public string PostNew(string url, string data, string strAuthorization = null, string tenant = null, bool IsSaas = false)
{
string ReadToEnd = "";
try
{
label1.Text = DateTime.Now.ToString();
System.GC.Collect();
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback((object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) =>
{
return true; //Always accept
});
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
| SecurityProtocolType.Tls;
//|(SecurityProtocolType)0x300;
//| (SecurityProtocolType)0xC00; //Tls12
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/json;charset=utf-8";//"application/json"
// = false;
request.Timeout = TimeOut;
request.ReadWriteTimeout = TimeOutReadWrite;
request.ServicePoint.Expect100Continue = false;
System.Net.ServicePointManager.DefaultConnectionLimit = 65500;
request.Proxy = null;
request.AllowWriteStreamBuffering = false;
request.ServicePoint.UseNagleAlgorithm = false;
//if (!(strAuthorization) && IsSaas)
// (, "Bearer " + strAuthorization);
//if (!(tenant) && IsSaas)
// (_tenant, tenant);
byte[] byteData = System.Text.Encoding.UTF8.GetBytes(data.ToString());
request.ContentLength = byteData.Length;
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}
//Response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
ReadToEnd = reader.ReadToEnd();
}
label2.Text = DateTime.Now.ToString();
}
catch (Exception ex)
{
throw new ApplicationException("An exception occurred connecting to the server (#" + ex.Message + ")");
}
return ReadToEnd;
}