<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi,<br>
you will probably find what you need by looking at the source code of my RTChecker project.<br>
Look here: <a class="moz-txt-link-freetext" href="https://www.assembla.com/spaces/rtcheckerv2">
https://www.assembla.com/spaces/rtcheckerv2</a><br>
<br>
Hope this helps<br>
Cris<br>
<br>
<br>
<div class="moz-cite-prefix">On 05/01/2015 04:39 PM, Tim Elkin wrote:<br>
</div>
<blockquote cite="mid:CAA=Bx5DVGDaQCaU5C407GHgL=Rf_jysTwmFfjfCuYAUfFm89Uw@mail.gmail.com" type="cite">
<div dir="ltr">
<div>
<div>Our goal is to create a Ticket in RT using VBA using the WinHttpRequest object.  We understand that there are 2 login pages involved with RT.
<br>
<br>
So, first we log into the first RT login page using using a "POST" request and passing the username and password using the SetCredentials function of the WinHttpRequest object.  This request appears to return a valid session cookie which we parse to use in
 our second WinHttpRequest request.<br>
<br>
</div>
In making our second request we use a "GET" request setting the 2nd RT login username and password using the SetCredentials function and in addition we now are passing the session cookie (that is we send a portion of the session cookie returned from the previous
 request) info using the SetRequestHeader (as in SetRequestHeader "Cookie", mvarSessionCookie ).  In this second request we are asking for an RT Ticket to be returned using
<a class="moz-txt-link-rfc2396E" href="https://(oururl)/REST/1.0/ticket/(aticket#)/show">
"https://(our url)/REST/1.0/ticket/(a ticket #)/show"</a>.  However, we receive the 401 Authorization error instead.<br>
<br>
</div>
<div>Some sample code would be great.<br>
</div>
<div><br>
</div>
<div><b>Below is the code we are using presently to verify that the session cookie we receive from the 1st RT login page is valid by
<br>
</b></div>
<div><b>using a second request to return an existing RT ticket (which is hard coded for testing purposes):<br>
</b><br>
</div>
<div>    Private Const cnstBase_URL As String = "<a class="moz-txt-link-freetext" href="https://[our">https://[our</a> RT url]"<br>
<br>
    With WinHttpReq<br>
        'either of the following lines seems to work and return a cookie<br>
        .Open "POST", cnstBase_URL<br>
        <br>
        .SetRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0"<br>
        .SetRequestHeader "Connection", "keep-alive"<br>
        <br>
        'user name and password for 1st RT login page/url<br>
    .SetCredentials cnstRequestor, cnstPWD, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER<br>
<br>
        On Error Resume Next<br>
        .Send<br>
        <br>
        If Err.Number = 0 Then<br>
            If .Status = "200" Then<br>
                On Error Resume Next<br>
                output_Cookie = .getResponseHeader("Set-Cookie")<br>
                On Error GoTo 0<br>
        <br>
                myCookie = Split(output_Cookie, ";")<br>
                If UBound(myCookie) > 0 Then<br>
                    'implicit conversion to string<br>
                    mvarSessionCookie = myCookie(0)<br>
                End If<br>
            Else<br>
                Debug.Print "HTTP " & .Status & " " & .StatusText<br>
            End If<br>
        Else<br>
            Debug.Print "Error " & Err.Number & " " & Err.Source & " " & Err.Description<br>
        End If<br>
        On Error GoTo 0<br>
        <br>
    End With<br>
<br>
    Set WinHttpReq = Nothing<br>
<br>
    If Trim(mvarSessionCookie) = "" Then Exit Function<br>
    <br>
    'perform second request<br>
    Set WinHttpReq = New WinHttp.WinHttpRequest<br>
    With WinHttpReq<br>
        'get ticket data<br>
        Dim TargetURL As String<br>
        <br>
        'to test cookie, display a ticket<br>
        'hard coded for testing as this works from the Browser which I thought would be a good test<br>
        'to see if the Cookie variable works<br>
        TargetURL = "<a class="moz-txt-link-freetext" href="https://[our">https://[our</a> RT url]/REST/1.0/ticket/96494/show"<br>
        <br>
        .Open "GET", TargetURL, False<br>
<br>
        .SetRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0"<br>
        .SetRequestHeader "Connection", "keep-alive"<br>
<br>
        .SetRequestHeader "Cookie", mvarSessionCookie<br>
<br>
        'user name and password for 2nd RT login page/url<br>
    .SetCredentials cnstBasic_Auth_User, cnstBasic_Auth_PWD, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER<br>
<br>
        On Error Resume Next<br>
        .Send<br>
        <br>
        If Err.Number = 0 Then<br>
            If .Status = "200" Then<br>
                Debug.Print<br>
                Debug.Print .ResponseText<br>
                Debug.Print .GetAllResponseHeaders<br>
            Else<br>
                Debug.Print "HTTP " & .Status & " " & .StatusText<br>
            End If<br>
        Else<br>
            Debug.Print "Error " & Err.Number & " " & Err.Source & " " & Err.Description<br>
        End If<br>
        On Error GoTo 0<br>
    <br>
        Debug.Print .GetAllResponseHeaders<br>
        <br>
    End With<br>
<br>
    Set WinHttpReq = Nothing<br>
<br>
</div>
<div><br>
</div>
<div>Thanks, in advance,<br>
</div>
<div>
<div>
<div>
<div>
<div class="gmail_signature">Tim<br>
<br>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<br>
</body>
</html>