飞信发信息,解决证书问题
private void button1_Click(object sender, EventArgs e)
{
ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();
string num = textBox1.Text;
string contents = textBox2.Text;
string url = "https://sms.api.bz/fetion.php?username=1511111111&password=11111111&sendto=" + num + "&message=" + contents;
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
req.Method = "GET";
using (WebResponse wr = req.GetResponse())
{
MessageBox.Show("OK");
}
}
internal class AcceptAllCertificatePolicy : ICertificatePolicy
{
public AcceptAllCertificatePolicy()
{
}
public bool CheckValidationResult(ServicePoint sPoint,
X509Certificate cert, WebRequest wRequest, int certProb)
{
// Always accept
return true;
}
}
private bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}