Tengo este codigo que funciona bien
Código
Dim webStream As Stream Dim webResponse = "" Dim request As HttpWebRequest Dim res As HttpWebResponse cookies = New CookieContainer request = CType(WebRequest.Create("https://host/"), HttpWebRequest) request.Method = "GET" request.AllowAutoRedirect = True request.CookieContainer = cookies request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0" request.Headers.Add("Upgrade-Insecure-Requests", "1") request.Headers.Add("Accept-Language", "es-ES,es;q=0.9") request.Host = "host" request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" request.KeepAlive = True res = CType(request.GetResponse(), HttpWebResponse) ' Send Request webStream = res.GetResponseStream() ' Get Response Dim webStreamReader As New StreamReader(webStream) While webStreamReader.Peek >= 0 webResponse = webStreamReader.ReadToEnd() End While
Aqui el servidor me da una cookie que guardo en el container y la envio en un POST, pero ya despues el servidor me devuelve una cookie nueva y nose como almacenarla, este es el codigo del POST
Código
' Set the Method property of the request to POST. request1.Method = "POST" request1.Host = "secure.etecsa.net:8443" request1.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0" request1.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" request1.Referer = "https://secure.etecsa.net:8443/" ' Set the ContentType property of the WebRequest. request1.ContentType = "application/x-www-form-urlencoded" request1.CookieContainer = cookies request1.Connection = HttpRequestHeader.KeepAlive request1.Headers.Add("Accept-Encoding", "gzip, deflate, br") request1.Headers.Add("Accept-Language", "en-US,en;q=0.5") Dim byteArray() As Byte = Encoding.UTF8.GetBytes(postData) ' Set the ContentLength property of the WebRequest. request1.ContentLength = byteArray.Length ' Get the request stream. Dim dataStream As Stream = request1.GetRequestStream ' Write the data to the request stream. dataStream.Write(byteArray, 0, byteArray.Length) ' Close the Stream object. 'dataStream.Close() ' Get the response. Dim response As WebResponse = request1.GetResponse() 'request1.GetResponse().Close() ' Display the status. 'MessageBox.Show(CType(response, HttpWebResponse).StatusDescription) ' Get the stream containing content returned by the server. dataStream = response.GetResponseStream ' Open the stream using a StreamReader for easy access. Dim reader As StreamReader = New StreamReader(dataStream) ' Read the content. Dim responseFromServer As String = reader.ReadToEnd ' Display the content. 'MessageBox.Show(responseFromServer) ' Clean up the streams. reader.Close() dataStream.Close() response.Close()
Alguna idea??
Es que estoy seguro que para cerrar la sesion la voy a necesitar.
Saludos