Thang Nguyen Posted December 15, 2020 Report Posted December 15, 2020 Hi everyone, I am start working on a project require to communicate with a web service (written by another team). I have to use POST HTTP function to request access token with provide username, password and tenant name in JSON format. I use Flatten to JSON to convert a cluster to JSON string for buffer. I have connect URL as it suppose to be. I event use string constant to pass in the JSON directly, but when I ran, it returned header: HTTP/1.1 401 UNAUTHORIZED Date: Tue, 15 Dec 2020 04:05:22 GMT Content-Type: application/json Content-Length: 44 Connection: keep-alive Access-Control-Allow-Origin: * Server: Werkzeug/0.14.1 Python/3.7.2 body: {"message":"Error in Database connnection"} The another team told me to test with Postman and it run fine with the same input URL and JSON data. It returns the correct access token. I am not sure what the different between my labVIEW code and the Postman structure. I don't have much experience with HTTP and Web service through so I ask for your inputs. Thank you very much in advance. Quote
LogMAN Posted December 15, 2020 Report Posted December 15, 2020 Do you receive any error at the error output terminal? Does the other team see any error in the server logs? Did the other team give you any idea about what kind of web service they provide? Since the other team suggested Postman, chances are high that they use a RESTful service. JKI has a REST API Client library on their website which you could try: JKI HTTP REST API Client for LabVIEW Quote
Rolf Kalbermatter Posted December 15, 2020 Report Posted December 15, 2020 4 hours ago, Thang Nguyen said: Hi everyone, I am start working on a project require to communicate with a web service (written by another team). I have to use POST HTTP function to request access token with provide username, password and tenant name in JSON format. I use Flatten to JSON to convert a cluster to JSON string for buffer. I have connect URL as it suppose to be. I event use string constant to pass in the JSON directly, but when I ran, it returned header: HTTP/1.1 401 UNAUTHORIZED Date: Tue, 15 Dec 2020 04:05:22 GMT Content-Type: application/json Content-Length: 44 Connection: keep-alive Access-Control-Allow-Origin: * Server: Werkzeug/0.14.1 Python/3.7.2 body: {"message":"Error in Database connnection"} The another team told me to test with Postman and it run fine with the same input URL and JSON data. It returns the correct access token. I am not sure what the different between my labVIEW code and the Postman structure. HTTP Error 401: https://airbrake.io/blog/http-errors/401-unauthorized-error#:~:text=The 401 Unauthorized Error is,client could not be authenticated.&text=Conversely%2C a 401 Unauthorized Error,to provide any such authentication. Somehow your HTTP server seems to require some authentication and you have not added any header to the query that provides such authentication. 1 Quote
Thang Nguyen Posted December 15, 2020 Author Report Posted December 15, 2020 @Rolf You are correct about header. I added a header I can find on NI forum as below and it works. Thank you for your input 1 Quote
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.