Showing results for 
Search instead for 
Did you mean: 

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

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?
Message 1 of 34
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 ( .
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
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
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
Accepted by topic author 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

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

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

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

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.


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




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
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

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.

0 Kudos
Message 9 of 34

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@

Download All
0 Kudos
Message 10 of 34