Вот код:
WebClient wc = new WebClient();
NameValueCollection parms = new NameValueCollection();
parms.Add("MMObjectType", "0");
parms.Add("MMObjectID", "");
parms.Add("To", number);
parms.Add("Msg", message);
parms.Add("Lang", "2");
wc.Headers.Add("Content-type", "application/x-www-form-urlencoded");
wc.UploadValues(Url, "POST", parms);
Падает на этапе UploadValues с сообщением
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
Включил лог сокетов, посмотрел процесс установления соединения.
System.Net Information: 0 : [2208] SecureChannel#10261382 — Remote certificate has errors:
System.Net Information: 0 : [2208] SecureChannel#10261382 — Unknown error.
System.Net Information: 0 : [2208] SecureChannel#10261382 — Remote certificate was verified as invalid by the user.
System.Net Error: 0 : [2208] Exception in the HttpWebRequest#45523402:: — The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
System.Net Error: 0 : [2208] Exception in the HttpWebRequest#45523402::EndGetRequestStream — The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
Запустил браузер со ссылкой на url — действительно ругается на сертификат, ибо он не соответствует домену.
в IE например можно просто нажать Yes и установить SSL даже с этим сертификатом.
А как это сделать в WebClient?... << RSDN@Home 1.1.4 stable SR1 rev. 568>>
Здравствуйте, denisio_mcp, Вы писали:
_>Вот код:
_>_>WebClient wc = new WebClient();
_>NameValueCollection parms = new NameValueCollection();
_>parms.Add("MMObjectType", "0");
_>parms.Add("MMObjectID", "");
_>parms.Add("To", number);
_>parms.Add("Msg", message);
_>parms.Add("Lang", "2");
_>wc.Headers.Add("Content-type", "application/x-www-form-urlencoded");
_>wc.UploadValues(Url, "POST", parms);
_>
_>Падает на этапе UploadValues с сообщением The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
_>Включил лог сокетов, посмотрел процесс установления соединения.
_>_>System.Net Information: 0 : [2208] SecureChannel#10261382 — Remote certificate has errors:
_>System.Net Information: 0 : [2208] SecureChannel#10261382 — Unknown error.
_>System.Net Information: 0 : [2208] SecureChannel#10261382 — Remote certificate was verified as invalid by the user.
_>System.Net Error: 0 : [2208] Exception in the HttpWebRequest#45523402:: — The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
_>System.Net Error: 0 : [2208] Exception in the HttpWebRequest#45523402::EndGetRequestStream — The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
_>Запустил браузер со ссылкой на url — действительно ругается на сертификат, ибо он не соответствует домену.
_>в IE например можно просто нажать Yes и установить SSL даже с этим сертификатом. А как это сделать в WebClient?
Была у меня та же проблема, правда пользовался не WebClient а HttpWebReqest
Попробуй добавить такой код
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
где TrustAllCertificatePolicy
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography.X509Certificates;
namespace mynamespace
{
class TrustAllCertificatePolicy : System.Net.ICertificatePolicy
{
public TrustAllCertificatePolicy() {}
public bool CheckValidationResult(System.Net.ServicePoint sp, X509Certificate cert,System.Net.WebRequest req, int problem) { return true; }
}
}