From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I send an HTTP request to a web server using the TCP functions?

Solved!
Go to solution
I'm trying to write an HTTP string to activate a CGI script our company server. It seems that the TCP OPEN CONNECTION is working. Can I simply use the TCP WRITE function to send the HTTP resquest string to the server?
Thanks,
Tim
Message 1 of 34
(44,733 Views)
Hi Tim,
You have to connect to port 80 of the server (like any other TCP connection) send your "request" and read the resopnse. You also need to know the specifications for GET and/or POST (http://www.faqs.org/rfcs/rfc2068.html) .
Note that the connection it will be closed after each response.

good luck

p.s.: I never tried with CGI but it should work.
0 Kudos
Message 2 of 34
(44,727 Views)
Thanks for pointing me in the right direction. I wasn't sure if it was even possible when I started out. I probably would have had to get the Internet Toolkit just for this application. I still want the toolkit, but is was nice to finish this project without extra expense.

It was an ASP and not a CGI, my mistake.
0 Kudos
Message 5 of 34
(44,727 Views)
Try the Internet Toolkit functions.

I created a form in HTML, sent it throught the the browser to the LabVIEW server to activate a CGI script written in LabVIEW. The reverse should be just as easy.

The Internet Toolkit has a number of functions devoted to exactly what you are trying to do.

Of course, you can do it the hard way and make manual calls to port 80, as suggested below. Personally, I like the Internet Toolkit. They have a great variety of samples included as well.

Good luck
0 Kudos
Message 3 of 34
(44,727 Views)
Solution
Accepted by Tim.S
I realize I probably would have finished faster if I had the Internet Toolkit, but the solution ended up being pretty simple with just the TCP functions.
Here's the solution I came up with yesterday (in case anyone else has the need) after researching TCP protocols as suggested by "Lab Viewer" and reviewing more info in the Developer Exchange. It ended up being only a 4 line string.

GET HTTP://proxyserver/path/file.asp?id=test HTTP/1.1
HOST:proxyserver



The first line of the string is composed of three things:
1) the GET command
2) the URL of target program (in this case an ASP program which distributes a predefined email message)
NOTE that in this case, the URL included "HTTP://proxyserver" and not just the file path. If your not using a proxy server, then you can probably omit the server name from the URL, but you still need the host server name in the second line.
3) the HTTP version used

The second line is the host server.

The last two lines are blank, but both are apparently necessary to properly close the TCP request.

The vi uses a TCP OPEN CONNECTION to connect to port 80, then the 4 line string is sent with a TCP WRITE and the connection is closed with a TCP CLOSE CONNECTION.

In my application, when the piece of equipment monitored by LabVIEW starts to go into an unsafe operating condition, LabVIEW uses this vi to send the HTTP request through the TCP connection and to a target ASP program on the company web server. The ASP reads the message ID (?id=test) and sends the appropriate email message and text page to maintenance and engineering personnel. The people notified by text pager are expected to respond immediately.

Our IS department wrote the ASP which allows us to define multiple message IDs all with different distribution lists. Each message is triggered with a different ID from the virtual instrument depending on the seriousness of the situation.

Thanks to the other enthusiasts who posted their questions and answers. Hope someone else finds this useful.
0 Kudos
Message 4 of 34
(44,728 Views)

This thread is quite old, but it's the first hit for a search with the terms "http get tcp", so I figure this is the best place to add my suggestion (even though it doesn't address the OP's question). The easiest way to get up and running with HTTP requests is with a pair of examples from DevZone [1]. I was able to modify the "Example HTTP GET method" VI to use the HEAD request instead (which is a way to check for the existence of a file on a server without fetching it).

 

[1] Example HTTP Protocols

http://zone.ni.com/devzone/cda/epd/p/id/3153

Joe Friedchicken
NI Configuration Based Software
Get with your fellow OS users
[ Linux ] [ macOS ]
Principal Software Engineer :: Configuration Based Software
Senior Software Engineer :: Multifunction Instruments Applications Group (until May 2018)
Software Engineer :: Measurements RLP Group (until Mar 2014)
Applications Engineer :: High Speed Product Group (until Sep 2008)
0 Kudos
Message 6 of 34
(44,028 Views)

I have a IP POWER Switch 9258 that Supports HTTP, DDNS , SMTP, SNMP, INTERNET- fixed IP, DHCP, LAN - virtual IP.  

 

I am attempting to issue a Http command via labview 8.2 to turn on and off the individual switches. 

 

ftp://ftp.opengear.com/manual/IP%20POWER%209258%20Quick%20Start%20and%20User%20Manual.pdf.

 

In the documentation on page 19 of 24, it says to use the following command in a browser: 

 

http://admin:12345678@192.168.0.50/Set.cmd?CMD=SetPower+P60=1+P61=0+P62=0+P63
=1

 

However when I attempt to us a linux browser with this command nothing happens. I can however login to the page by specifying the IP Address and at the page logging into the device.  Ultimately I am attempting to use TCP vi's to post this command line from my vi.

 

 Any ideas on using the TCP vi with this requirement?

0 Kudos
Message 7 of 34
(43,859 Views)
I was able to get the browser in both Windows and Linux to activate the switch.  Now just working on the TCP passive and active vi's.
0 Kudos
Message 8 of 34
(43,843 Views)

Hi Jeff,

 

It sounds like you have found the Active and Passive example VIs, great! You indicated that you were having trouble getting it to work in Linux and Windows, what changed to make it start working? Have you tried using a packet sniffer like WireShark? Perhaps there is information that is not getting sent with the TCP VIs.

Joshua B.
National Instruments
0 Kudos
Message 9 of 34
(43,785 Views)

I think so far the problem is I am not sending the correct Posting header?  I worked with Example_HTTP, specifically the POST vi.  This activates all the switches to on.  Here is what I am trying to pass to the server:

 

POST http://admin:12345678@192.168.0.50/Set.cmd?CMD=SetPower+P60=1+P61=0+P62=0+P63
=1

Download All
0 Kudos
Message 10 of 34
(43,740 Views)