martin_h Posted June 28 Report Share Posted June 28 Hi I try to communicate with a network recorder. using HTTP Rest api. Here an Example from the Manual: curl -k https://192.168.153.193:8443/api/v1/settings/stream/status/1 Answer: { "status": "Enable" } That also works in LabVIEW which is great so far. When I try to use the POST I do fail with LabVIEW Here an example from the Manual using Post: curl -k --basic -u JohnDoe:123456 -X POST https://192.168.153.193:8443/api/v1/settings/stream/status/1 -d "{\"action\": \"save\",\"data\": {\"status\": \"Enable\"}}" I tried the above POST command using "putty" - so I know, that it should work according to the manual. Following picture shows the implementation in LabVIEW. As you see, I get the right ansver for GET but I get "Unauthorised" Response wit Error code 401. Any Idea how I can solve this? Quote Link to comment Share on other sites More sharing options...
martin_h Posted June 28 Author Report Share Posted June 28 (edited) Update: I just saw that above Post Command: curl -k --basic -u JohnDoe:123456 -X POST https://192.168.153.193:8443/api/v1/settings/stream/status/1 -d "{\"action\": \"save\",\"data\": {\"status\": \"Enable\"}}" also works in Cmd Window 🙂 So I also tried out the System Exec.vi and that also works. So basically Problem solved but just with a workaround. Basically I can do both now using System Exec.vi => GET and POST But I still wonder: Is there an idea how to do it using REST API? Edited June 28 by martin_h Quote Link to comment Share on other sites More sharing options...
martin_h Posted July 9 Author Report Share Posted July 9 (edited) Hi Problem solved within LabVIEW (thx to Support from NI). (Translated from german sorry guys) When an HTTP request is sent using LabVIEW, the authorization headers are not added to the request, so the server rejects the request. LabVIEW should actually add the Authorization headers automatically when these fields are used in the Open HTTP Handle.vi file, but the following figure shows that there are no headers. Therefore, a colleague of mine created a VI that creates the headers manually. With this VI I can now make POST requests to endpoints that require authentication. As you see from NI Example I need to send the basic Authorisation using the Add Header vi. Kinda special for me is, that there is/was not yet an entry in the combobox for Authorisation. The base64 fast encode 2012 NIVerified.vi id used to encode the username:password string. Following 2 examples (Both work). First using LabVIEW 2019 HTTP functions. Second using JKI Rest API using LabVIEW 2023. Someting that was wrong in my case was that I have not removed the back slash in the send data. "{\"action\": \"save\",\"data\": {\"status\": \"Enable\"}}" => {"action": "save","data": {"status": "Enable"}} Edited July 9 by martin_h Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.