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 finally got it! I used wget.  Thanks
0 Kudos
Message 11 of 34
(5,448 Views)

I see that this is a very old posting, however, it's now become relevant to me.  I was wondering, you mention, "Note that the connection it will be closed after each response."  How does the connection close after each reponse?  Wouldn't it only it only close if I call the Close_TCP_Connection VI?  I'm trying to talk to a radio and the first message after the open connection seems to be ok, but subsequent messages don't get a reply.  I'm pretty sure that the http I'm sending is ill-formed.  Regardless, can't I keep the connection open till done?  I have a number of messages that I want to send back and forth and I didn't plan on closing the connection until the user wants to.  Is that a problem?

 

Also, outside of the Internet Toolkit, are there any VIs that help construct well-formed http.  I'm having to manually construct all of my headers/body, and this is prone to errors.

0 Kudos
Message 12 of 34
(5,342 Views)

mrbean wrote:

I see that this is a very old posting, however, it's now become relevant to me.  I was wondering, you mention, "Note that the connection it will be closed after each response."  How does the connection close after each reponse?  Wouldn't it only it only close if I call the Close_TCP_Connection VI?  I'm trying to talk to a radio and the first message after the open connection seems to be ok, but subsequent messages don't get a reply.  I'm pretty sure that the http I'm sending is ill-formed.  Regardless, can't I keep the connection open till done?  I have a number of messages that I want to send back and forth and I didn't plan on closing the connection until the user wants to.  Is that a problem?

 

Also, outside of the Internet Toolkit, are there any VIs that help construct well-formed http.  I'm having to manually construct all of my headers/body, and this is prone to errors.


Default operation for a HTTP server is to close the socket after each HTTP transmission. So this means that trying to reuse a connection after a single send/receive operation is normally not possible. If you implement HTTP 1.1 on the client side and send a correct HTTP 1.1 header with the additional parameter "Connection: Keep-Alive", then you can continue to reuse the connection as long as the server responds with a header that states that it supports HTTP 1.1 or better.

Rolf Kalbermatter
My Blog
0 Kudos
Message 13 of 34
(5,321 Views)

I do use the "Connection: Keep Alive", so  I should be ok there.  In a related question, I'm using Stunnel to talk to this radio, and although my log says I'm binding to the IP addr, I'm seeing no data.

 

A different person told me, after examining my .conf and log files that he noticed that stunnel is using the SSL certificate from its own directory (C:\Program Files\stunnel\stunnel.pem), but should instead use the SSL certificate from the server, since each server has a different SSL cert.

 

Is the location of the server's SSL certificate something I should know?

 

 

0 Kudos
Message 14 of 34
(5,310 Views)

I (ultimately) have a question about Stunned.  I've been manually constructing the http messages that I have to send to the radio based on what I'm seeing go across (in a non-secure mode) using a sniffer program called WireShark.  Here's a sample of the data I see going across, and that I'm trying to emulate.

 

GET /setupRfData.asp HTTP/1.1\r\n
[truncated] Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/
    Referer: http://10.4.30.1/\r\n
    Accept-Language: en-us\r\n
    Accept-Encoding: gzip, deflate\r\n
    User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 3.0.04506.30; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)\r\n
    Host: 10.4.32.1\r\n
    Connection: Keep-Alive\r\n
    Authorization: Basic YWRtaWtcoirldOvcmQx\r\n
        Credentials: admin:Paxxword1
    \r\n

 

A lot of the information in the GET above is standard (I'm told), but I also do POST commands where I have to insert actual data.  By 'Standard', I mean that, I guess, Internet Explorer takes care of when it establishes a link.  Right now, the GET/POST messages I send are entirely produced (headers/data/footers) by me and sent via TCP-Write (currently in a non-secure fashion, but ultimately (I pray) securely using Stunnel).  Does Stunnel take care of header/footer details or does it simply (I don't think any of this is simple) establish the connection and take care of getting the message traffic from A to B?

 

I'm not sure what to do when I see '[truncated]'.  Also, since I don't need to process the html coming back to me, I don't think I need to Accept all the applications listed.  Similarly, with the User-Agent field - do I have to list all those things when I don't plan to process the html, just simply display it in a text form?

0 Kudos
Message 15 of 34
(5,283 Views)
Of course I meant "Stunnel", not 'Stunned' - even though that's how I feel right now.
0 Kudos
Message 16 of 34
(5,280 Views)

mrbean wrote:

I (ultimately) have a question about Stunned.  I've been manually constructing the http messages that I have to send to the radio based on what I'm seeing go across (in a non-secure mode) using a sniffer program called WireShark.  Here's a sample of the data I see going across, and that I'm trying to emulate.

 

GET /setupRfData.asp HTTP/1.1\r\n



stunnel will only look at this line. Because it needs to know to which server to send the information you do provide in the GET command a fully qulified URL with the server address prepended to the path. Basically stunnel acts as HTTP proxy, in the process of proxying it does however also encrypt the non encrypted stream into an SSL encrypted stream and vice versa.

 

I have been working on a replacement library for the TCP/Ip functions a little more, and it seems I'm getting somewhere with the TCP/IP functionality mostly working as the LabVIEW functions do, but with the additional feature to support IP6 and hopefully SSL. I even got a first connection to a HTTPS server established to get some data from it, but have still a few stability problems with that. So don't hold your breath for this.

Rolf Kalbermatter
My Blog
0 Kudos
Message 17 of 34
(5,274 Views)
Can you provide an example of a "fully qualified URL with server address prepended to the path".  I thought that the stunnel.conf file took care of all that.  Your saying I have to provide this info in the GET and POST messages I send?
0 Kudos
Message 18 of 34
(5,259 Views)

That is at least how I did it. You probably can get stunnel to contact a specific server always, but it is of course much more practical to have stunnel take the address from the GET command (and possibly POST too but I never tried that).

 

The way your absolute URI command would look is something like this:

 

GET http://www.w3.org/pub/WWW/TheProject.html HTTP/1.1\r\n

 while for a non proxy request it would be:

 

GET /pub/WWW/TheProject.html HTTP/1.1\r\n

 

In theory every HTTP server can also work as proxy but in practice it is not usually common to do that, and some servers might disable that to limit bandwith usage.

Message Edited by rolfk on 10-29-2009 10:51 PM
Rolf Kalbermatter
My Blog
0 Kudos
Message 19 of 34
(5,248 Views)

I have an IP address instead of a URI, so I assume my call would look like this

 

GET 10.4.32.1 HTTP/1.1\r\n

 

One question, you said ...

"but it is of course much more practical to have stunnel take the address from the GET command"

 

I'm not sure how stunnel "takes" the address from the GET command.  I thought stunnel looked at what you had in the stunnel.conf in the [https] accept.  Is that not correct?

 

[https]
connect  = 80
accept   = 10.4.32.1:443
TIMEOUTclose = 0

 

0 Kudos
Message 20 of 34
(5,238 Views)