LabVIEW Web Development Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview POST, PUT HTTP method

Solved!
Go to solution

I have similar problem. I want to send text messages using twilio api from labview. For that I am using HTTP POST method in LabVIEW. 

I am not able to determine how to send form-data using POST.vi. I have tested the same using postman, and it is working fine, with Body in postman as : 

Body

form-data

Body : "Text Message"

To : "Receiver's number"

From : "Sender's Number"

 

I want to send the above data using POST.vi. I have already tried few things like:

Converting the above data to JSON  and feeding it to Buffer input of POST.vi as 

      {"Body" : "Text message"

        "To" : "Receiver's number"

        "From": "Sender's number"

       }

 

and 

 

{ "parameters" : [{"Body" : "Text message"

        "To" : "Receiver's number"

        "From": "Sender's number"

       }]

}

 

 

 

0 Kudos
Message 21 of 30
(5,998 Views)

Hi all,

 

I need transfer a file to device using HTTP. This is example how it's working using cURL (https://curl.haxx.se/)

 

curl -H "Expect:" http://192.168.0.0/controller/putfile -F username=MyUser -F password=MyPassword -F filetype=setupfile -F input_file=@setup.xml

 

But I really don't how convert it to LabView using POST or PUT method. Somebody helps?

 

 

Message 22 of 30
(5,739 Views)

Hi Milan

How can we got the  case name Authorization?

 

auth.PNG

0 Kudos
Message 23 of 30
(5,121 Views)

Hi all,

                When i use Labview Post.vi to tansfer date, it can correct receive date. but display date formate error.

when i use postman send the same date, it can receive success.  The Labview and postman header difference is content - Length,Labview is 48 and postman is 35.

                The buffer data is:

{

"SiteInfo": {

"SiteWorkers": "000",

"SiteLocation": "12",

"SiteDataType": "老化",

"SiteIP": "192.168.40.103"

},

"SiteDatas": [

{

"ProductModel": "LT150EH161D105",

"Number": "1",

"Barcode": "H181603800000",

"AgingDatas": [

{

"DateTime": "2018-01-10 12:47:22",

"Temperature": "30",

"VoltageMax": "",

"Voltage": "233.650",

"VoltageMin": "",

"PowerMax": "300",

"Power": "151.69",

"PowerMin": "100",

"PFMax": "1",

"PF": "0.97",

"PFMin": "0.8",

"CurrentMax": "",

"Current": "0.649",

"CurrentMin": "",

"Result": "PASS"

},

{

"DateTime": "2018-01-10 13:18:50",

"Temperature": "30",

"VoltageMax": "",

"Voltage": "231.200",

"VoltageMin": "",

"PowerMax": "150",

"Power": "66.59",

"PowerMin": "30",

"PFMax": "",

"PF": "0.88",

"PFMin": "",

"CurrentMax": "",

"Current": "0.288",

"CurrentMin": "",

"Result": "PASS"

}

]

}

]

}

            can you help me?

            the attach is the Labview and postman pictrue.

 

thanks

andy

0 Kudos
Message 24 of 30
(5,051 Views)

Hi Andy,

 

Can you put this to a new thread? It may get seen by more people than adding to an existing one.

 

I can prime you with some more questions though: 

 

* What are you sending data to?

* Is it right that the application you send data to complains about the date format?

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
0 Kudos
Message 25 of 30
(5,042 Views)

There is no apikey in the header. If forced to enter, the returned result will prompt an error. Please also help me check the reason.111.PNG22.PNG33.PNG

0 Kudos
Message 26 of 30
(3,321 Views)

已找到方法了,感谢大家

0 Kudos
Message 27 of 30
(3,312 Views)

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:

OSU101_0-1683235611014.png

 

 

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:

OSU101_1-1683235611176.gif

 

 

POST HELP page:

OSU101_2-1683235610982.gif

 

OSU101_3-1683235611010.gif

 

0 Kudos
Message 29 of 30
(3,054 Views)

我也在苦恼这个问题,你的方法能否分享一下,谢谢。

0 Kudos
Message 30 of 30
(2,531 Views)