Jump to content

Using REST (CURL) with options - Get works => Post error 401 Unauthorised

Recommended Posts

I try to communicate with a network recorder. using HTTP Rest api.
Here an Example from the Manual:
curl -k
"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 -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?

Link to comment
Share on other sites

Posted (edited)

I just saw that above Post Command:
curl -k --basic -u JohnDoe:123456 -X POST -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 by martin_h
Link to comment
Share on other sites

  • 2 weeks later...
Posted (edited)

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 by martin_h
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.