Code Snippet:
ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol
= SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
ServicePointManager.ServerCertificateValidationCallback = delegate (object s,
System.Security.Cryptography.X509Certificates.X509Certificate certificate,
System.Security.Cryptography.X509Certificates.X509Chain chain,
System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
return true;
};
var req = (HttpWebRequest)WebRequest.Create(@"https://example.com");
req.Method = "POST";
req.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes("userid:password"));
//req.Credentials
= new NetworkCredential("username", "password");
req.ContentType
= "application/json";
var reqbody = new Requestheaderdata()
{
timeoutseconds = "300",
userrole = "sample"
};
var requestData = JsonConvert.SerializeObject(reqbody);
var bytes = Encoding.ASCII.GetBytes(requestData);
req.ContentLength = bytes.Length;
using (var
outputStream = req.GetRequestStream())
{
outputStream.Write(bytes, 0,
bytes.Length);
}
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
No comments:
Post a Comment