1
When I have to play a few steps (GETS
and POSTS
) of an access all https using .net
I need the use of ServicePointManager.ServerCertificateValidationCallback
. Then there came my doubt, it is necessary to declare before making each web request, in each get or post, or just state in 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"
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"
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()
pointing out that the information is all fictitious.