LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to upload file using HTTP POST

i try to upload file to  server by HTTP POST

the server ask for login ( username , PW)

 

to run XML commands on this server i am using activeX -  MSXML2.IXMLHTTPRequest and all Ok .

can i use this Activx for upload file ?if yes how ?

 

can i use http Vis ? ( need exmple with login)

 

below i have exmple in .net how to that

 i tryed to connectivity to .net but not found the class  WebClien .....

 

thanks

 

WebClient wc = new WebClient();
                wc.Credentials = new NetworkCredential("Company", "Password");
                wc.Headers.Add("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
                wc.Headers.Add("Referer", "http://" + this.host + "/upgrade.html");
                wc.Headers.Add("Accept-Encoding", "gzip, deflate");
                wc.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; InfoPath.3)");
                wc.Headers.Add("Authorization", "Basic SGFybW9uaWM6aGxpdGluMQ==");
                //wc.UploadProgressChanged += new UploadProgressChangedEventHandler(wc_UploadProgressChanged);
                wc.UploadFileCompleted += new UploadFileCompletedEventHandler(UploadFileCallback);
                wc.UploadFileAsync(new Uri("http://" + this.host + "/InstallFirmware"), "POST", uploadfile);

 

 

0 Kudos
Message 1 of 7
(6,221 Views)

Look at the HTTP Post Multipart VI in the HTTP Client VIs - you should be able to POST your file using that by specifying the file path and field name in the bundle by name and then build array. To set the username/password (I'm assuming it's simple HTTP AUTH) you can specify those on the Open Handle VI.

 

The .NET web client should also work too (on Windows) - finding stuff in the .NET browser can be a pain but I'm sure it'll be there. Looking at the .NET help documentation on MSDN should help you to find it.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 2 of 7
(6,179 Views)
Hi Sam, You can send me an VI example. It does not work for me. can you pls write in the exmple how to work with login and the headers as write in .net . thanks .
0 Kudos
Message 3 of 7
(6,158 Views)

How about you post the VI you have created (screenshot, attach the VI (<= LV 2014) or create a VI snippet) to show what you have tried and I will look at it?


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 4 of 7
(6,155 Views)

i try to do that by .net . 

labview 2012 . 

attached the sendfile.vi 

0 Kudos
Message 5 of 7
(6,145 Views)

What is the error you are getting? 

 

If you're not registering for the callback event (you would need to create a callback VI etc.), I would try doing a synchronous file upload first so you can see if/when the upload completes.

 

I would think that if you don't leave the VI running with the asynchronous upload, it probably clears up all the .NET references when the VI stops running - terminating the webclient reference before the upload has completed. You can check this with the Desktop Execution Trace Toolkit.

 


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 6 of 7
(6,138 Views)
Good Day,

We're you able to send the file using http to the controller.?
I am currently trying to automatically send a file to a controller using labview.
The controller has a web service built and deployed on it. As of now I need to feed the ip of the controller in a web browser, then the username and password and i get interface from where I can upload the file.
I need to automate the procedure such that the file will get uploaded on the press of a button on my front panel.
I have tried the Post.vi and PostMultiPart.vi. They do not return a error when run but the file doesn't get transferred either.
Kindly help.


Regards.
Digant Shetty (LV 18.0)
AE, Combined Digilog Systems Pvt. Ltd.

CDSPL LOGO.pngAlliance Partner.png

0 Kudos
Message 7 of 7
(5,774 Views)