When I have to reproduce a few steps ( GETS
and POSTS
) of an access all https using .net
I need to use ServicePointManager.ServerCertificateValidationCallback
. So here's my question: do I have to declare before doing each web request, in every get or post , or just declare on my first request?
Below is an example of a request being made:
postData = postData & "-----------------------------296631985423887--"
ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateServerCertificate)
url = "https://www.google.com.br"
req = HttpWebRequest.Create(url)
req.Method = "POST"
req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:39.0) Gecko/20100101 Firefox/39.0"
req.Headers.Add(HttpRequestHeader.AcceptLanguage, "pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3")
req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
req.KeepAlive = True
req.Headers.Add(HttpRequestHeader.Cookie, sessao)
req.Referer = "www.google.com.br"
req.ContentType = "multipart/form-data; boundary=---------------------------296631985423887"
req.ContentLength = postData.Length
Dim swRequestWriter As StreamWriter = New StreamWriter(req.GetRequestStream())
swRequestWriter.Write(postData)
swRequestWriter.Close()
resp = req.GetResponse()
Emphasizing that the information is all fictitious.