0

I have a java application running like a server in Tomcat for my web app and my app cordova (same as the web application but with functions like a BarCode Scanner). With this application the server works perfectly. But now I am developing a little part of the aplication in VB.NET with compact framework 3.5 and when I log in the server store my session variable... Ok, that's fine but if I make a new request, my server detects a new session and for this my session variable is not here and for each request is opening a new Http Session. I think the problem is in VB. That's my code where I open requests to my server

 Try
            Dim url = "http://192.168.2.166:8084/SCTraker_Servidor/api/Session"
            Dim httpWebRequest As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
            httpWebRequest.Method = "POST"
            httpWebRequest.ContentLength = byteArray.Length
            httpWebRequest.ContentType = "application/json"

            Dim dataStream = httpWebRequest.GetRequestStream()
            dataStream.Write(byteArray, 0, byteArray.Length)
            dataStream.Close()

            Dim httpWebResponse As HttpWebResponse
            httpWebResponse = DirectCast(httpWebRequest.GetResponse, HttpWebResponse)

            If httpWebResponse.StatusCode = 200 Then
                Me.Hide()
                httpWebRequest.Abort()
                httpWebResponse.Close()
                Home.Show()
            Else
                BarraEstado.Text = "No ha rellenado el campo usuario o contraseƱa"
            End If

        Catch webException As WebException
            BarraEstado.Text = webException.Message
            Dim respuesta = webException.Response

        Catch socketException As Sockets.SocketException
            BarraEstado.Text = socketException.Message

        End Try
emilioxiri
  • 113
  • 2
  • 10

1 Answers1

0

When using Tomcat you have to use either the appended JSESSIONID parameter from the previous request or use the cookie JSESSIONID sent by the server.

When receiving the response from the Tomcat server look for a cookie named JSESSIONID and save it. In the next request set this coockie again.

If the server does not send a coockie then look for a String that starts with ;JSESSIONID=...appended to the URL after authenticated. Append this String to every request you make to the Tomcat server.

Uwe Plonus
  • 9,803
  • 4
  • 41
  • 48