05-04-2023 04:20 PM - edited 05-04-2023 04:21 PM
Hi,
I am new to labview and have been struggling with token management in Labview. I am creating a server that will interact with Labview. The user logs in using Labview's POST VI and a token cookie is returned. I am trying to save that cookie in a file inside Open Handle VI and need assitance. The goal is for after that step, Open Handle will automatically add the cookie to the headers for further API calls to my server.
From researching, I have found a few ideas. Attached is a block diagram from another post: https://forums.ni.com/t5/LabVIEW-Web-Development/Labview-POST-PUT-HTTP-method/td-p/3663058.
My first approach is manually saving the session token and my second approach is using the file path terminal in the Open Handle VI. I was hoping for clarification for both methods.
Approach 1:
1. After the POST request where we login to the server, we can use the header's terminal in the right output side to grab the session token.
2. We then store it in a local variable and wire it the value on the next 'Add Headers'
3. Then we make another POST call to the protected route with our cookie.
Open Handle --> POST --> local variable --> Add Header VI (cookie value) --> POST call ... -> Close Handle
Alternatively, just wire the cookie value from the get header to add header:
Open Handle --> POST --> Get Header VI (cookie value) --> Add Header VI (cookie value) --> POST call ... -> Close Handle
Block Diagram from Page 1:
Approach 2:
We start with the Open Handle and create an empty file SampleCookie.txt to the cookie file input.
Now the goal is for a future POST call to insert the cookie inside this file and then for Open Handle to automatically attach the cookie in the file to further API calls
My guess:
1. POST VI is wired to Get Header VI which gets the cookie value.
2. Get Header VI value is wired to "Write to File" with the file name as "sampleCookie.txt"(the same file as in the Open Handle VI).
3. Then the client handle is sent to our 2nd POST VI.
4. Since now the sampleCookie.txt has the cookie value in it, the Open Handle VI will automatically add the cookie header to my second POST VI call
5. It goes to the protected server route and the cookie is checked and other server logic.
6. We eventually close using Close Handle VI which deletes the cookie file.
My questions:
1. Did I do this right?
2. To store the cookie in the file do I have to change the formatting or anything?
3. Suggestions of more efficient method of approach 1 vs 2?
Below I attached help pages for Open Handle, Post, and a POST request with the SampleCookie.txt file path I mentioned.
OpenHandle HELP page:
POST HELP page: