Jump to content

HTTP Post does not work


Recommended Posts

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. 

image.png.aa7c77aa874cee82c4a335249170f7f4.png

image.png.b8e51edb424e416fd039942292293322.png

I don't have much experience with HTTP and Web service through so I ask for your inputs.

Thank you very much in advance.

 

 

Link to comment
  • 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
Link to comment
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.

  • Like 1
Link to comment

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.