LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

.NET Http/Https Get document

Has anyone used .NET to do Http/Https services ? I used activex to talk to a webserver and read the contents using "Get document". I want to see if I can do via .NET since activeX has some inherent problems such as the update speed or cacheing.

Thanks
Sridhar

Kudos are the best way to say thanks 🙂
0 Kudos
Message 1 of 21
(10,834 Views)
I haven't tried .NET, but one other option is to use DataSocket read function.

-Khalid
0 Kudos
Message 2 of 21
(10,822 Views)
Problem with data socket is: The first few characters sent have a bug. If you send "Passed", you would read it as "PPPPed"

I have used activeX before. It has some kind of cacheing when I do secure communication. ActiveX works fine if it http rather than https.

So I want to use .NET to see if it's any better.

Kudos are the best way to say thanks 🙂
0 Kudos
Message 3 of 21
(10,819 Views)
Sridhar,

From an NI perspective, I can offer support with how to use LabVIEW as a .NET client (linked below). I can also offer that I have not personally seen an application that utilized .NET to communicate with a web server. As for whether or not the functionality exists, I cannot say for sure. If you are able to utilize .NET to communicate with a web server, please post back to this forum, as I am also interested to know. Thanks,

Mike

Using .NET in LabVIEW:
http://zone.ni.com/reference/en-XX/help/371361A-01/lvconcepts/using__net_with_labview/
0 Kudos
Message 4 of 21
(10,789 Views)
Another aspect to keep in mind - the .NET APIs will let you communicate via HTTP and HTTPS. The next question is what to do with the data. If you are talking to a web service, receiving XML, you might want to use the Web Service Proxy support in .NET instead. If it's custom XML, then you can use the System.Xml classes. If it's HTML, you'll probably be better off using the IE control set in ActiveX.
 
Speaking from first-hand experience, processing HTML - especially being able to handle the variety out on the web, with CSS and JS additions - is a nightmare and you'd be better off using the MS HTML parser and it's associated DOM.
 
Guess I'm not answering your question as much as giving you more 🙂
0 Kudos
Message 5 of 21
(10,776 Views)
How you do communicate with HTTPS via .NET. Do you have an example ? I will be extracting the readout as a string and process them. I am thinking or hoping that .NET is better than activeX in communicating with HTTPS or atleast HTTP.

Kudos are the best way to say thanks 🙂
0 Kudos
Message 6 of 21
(10,757 Views)
The class you want is System.Net.HttpWebRequest, and the programming is pretty simple. I wipped up a quick example below. Note that my reading portion is very primative - it's a fixed size array. You'll probaby want to "read until done" or similar actions.
 
Unfortunately, the ContentLength is usually not helpful as it's often -1. This means that the web server didn't send the length - it expects the client to "read until done".
0 Kudos
Message 7 of 21
(10,753 Views)
Just in case someone stumbles on this thread, I've attached an extension to the .NET example shown by Lycangeek. This is a fairly quick web document fetcher (seems to be as fast as IE). There's probably a better way to do the proxy subsitution. That's required to prevent the first call from searching for a proxy (5 to 10 second delay).
 
The status code is a bitch sketchy right now as I'm searching for a .NET way to get this back using the WebRequest structure (Using .NET 2.0 here).
 
The image is big (sorry), so you may need to open up your browser window size to see it clearly. If you need help locating the .NET modules/assemblies, just let me know and I'll gather the list. You can likely find them faster searching http://msdn2.microsoft.com/en-us/library/aa139635.aspx for each method or property name.
Message 8 of 21
(10,413 Views)

One more question. Your code works great on HTTP and HTTPS. When I goto a website which asks me to accept the certificate, the code fails because by default it rejects the authentication.

 

I see system.security.authentication.authenticationexception and I think it's got to do something with it. Any ideas ?

 

 

Message Edited by Spartan00 on 06-03-2009 03:56 PM

Kudos are the best way to say thanks 🙂
0 Kudos
Message 9 of 21
(9,822 Views)

Here is a VI snippet for those interested in working with this code:

 

dotNET https.png

Misha
0 Kudos
Message 10 of 21
(9,643 Views)