vba как читать и хранить LTPA? - PullRequest
       21

vba как читать и хранить LTPA?

0 голосов
/ 18 сентября 2018

Я пытаюсь установить «тихое» соединение, используя WinHTTP или xmlHTTP, начиная с формы Excel и заканчивая нашей интрасетью.

Я только что написал код, который открывает IE, выполняет вход в систему, передает данные, компилирует форму и получает необходимую информацию. Теперь я хочу сделать то же самое без открытия сессии IE.

Я написал некоторый код и достиг цели войти в систему и «перейти» на следующую страницу, но я не могу продолжить. Я думаю, что это проблема с токеном LTPA. Я спрашивал раньше на форуме более общий пост.

Вот мой код

' Takes a string of the form "JSESSIONID=40DD2DFCAF24A2D64544F55194FCE04E;path=/pamsservices;HttpOnly"
' and returns only the portion "JSESSIONID=40DD2DFCAF24A2D64544F55194FCE04E"
Public Function GetJsessionIdCookie(setCookieStr As String) As String
    'JSESSIONID=40DD2DFCAF24A2D64544F55194FCE04E;path=/pamsservices;HttpOnly

    Dim jsessionidCookie As String

    Dim words() As String
    Dim word As Variant

    words = Split(setCookieStr, ";")
    For Each word In words
        If InStr(1, word, "JSESSIONID") > 0 Then
            jsessionidCookie = word
        End If
    Next word

    GetJsessionIdCookie = jsessionidCookie
End Function

Public Sub Login()
    Dim JUserid, userid As String
    Dim JPassword, password As String

    userid = "xxxxxx"
    password = "yyyyyyy"
    JUserid = "j_username=" & userid
    JPassword = "j_password=" & password

    Dim postReq, getReq, cookies
    Dim p0 As Integer, p1 As Integer, temp As String
    Dim result As String, respHead As String
    Dim http As Object

    Set http = CreateObject("WinHttp.WinHttpRequest.5.1") 'initialize  other CreateObject("MSXML2.serverXMLHTTP.6.0") or 'CreateObject("MSXML2.serverXMLHTTP.6.0")

    http.Open "GET", "http://kkkkkkk.it/Home/Logon.jsp", False
    http.setRequestHeader "Content-Type", "ext/html; charset=ISO-8859-1"
    http.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
    http.setRequestHeader "User-Agent", "MS Internet Explorer"
    http.send

    strCookie = http.getResponseHeader("Set-Cookie") ' --> "JSESSIONID=40DD2DFCAF24A2D64544F55194FCE04E;path=/pamsservices;HttpOnly"
    jsessionidCookie = GetJsessionIdCookie(strCookie)

    Debug.Print jsessionidCookie
    http.getAllResponseHeaders
    respHead = http.getAllResponseHeaders()
    'Debug.Print respHead
    'Debug.Print jsessionidCookie

    http.Open "GET", "http://KKKKKKKKK.it/Home/j_security_check", False
    http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    http.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
    http.setRequestHeader "User-Agent", "MS Internet Explorer"

    http.send

    http.getAllResponseHeaders
    respHead = http.getAllResponseHeaders()
    Debug.Print http.responseText
    Debug.Print respHead

    http.Open "POST", "http://kkkkkkk.it/Home/j_security_check", False
    http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    http.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
    http.setRequestHeader "User-Agent", "MS Internet Explorer"

    http.send JUserid & "&" & JPassword

    http.getAllResponseHeaders
    respHead = http.getAllResponseHeaders()

    http.Open "GET", "http://kkkkkk.it/Home/HomeServlet", False
    http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    http.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
    http.setRequestHeader "User-Agent", "MS Internet Explorer"
    http.send                                    '"Ric=informativa&informativa=true"

    http.getAllResponseHeaders
    respHead = http.getAllResponseHeaders()
    Debug.Print http.responseText
    Debug.Print respHead

    http.Open "post", "http://kkkk.it/Home/HomeServlet", False
    http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    http.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
    http.setRequestHeader "User-Agent", "MS Internet Explorer"
    http.send "Ric=informativa&informativa=true"

    respHead = http.getAllResponseHeaders
    Debug.Print http.responseText
    Debug.Print respHead

    ' this is the code that makes the error " Problems with authentication"
    http.Open "GET", "http://kkkkkkk.it/Uffici/WebServlet", False
    http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    http.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
    http.setRequestHeader "User-Agent", "MS Internet Explorer"
    ' http.setRequestHeader '"Set-Cookie", jsessionidCookie
    http.send
    respHead = http.getAllResponseHeaders
    Debug.Print http.responseText
End Sub

Я прошу прощения за мой плохой английский и за "ужасные ошибки", которые я сделал.

...