NetTalk Central

Author Topic: NetWebClient - Uploading a file to a NetWebServer  (Read 2883 times)

David

  • Full Member
  • ***
  • Posts: 127
    • View Profile
NetWebClient - Uploading a file to a NetWebServer
« on: October 22, 2010, 06:35:57 PM »
I'm not sure how to start this at all.... I have read through the posts regarding posting a file to a web server and am no closer to getting started.

I have a NetWebServer that displays a NetWebForm.  The only field on the form is a FileUpload field, and there is a save button.  Using NetWebClient, Can I fetch the page, set the element to the file name I want to upload and then "click" the save button?

Thank you for any help you can provide.
David.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11239
    • View Profile
Re: NetWebClient - Uploading a file to a NetWebServer
« Reply #1 on: October 23, 2010, 04:23:21 AM »
Hi David,

The short answer is yes. It's a fairly straight-forward operation.

Depending on how you've set it up, you can usually skip the first step. You often do not need to "fetch" the page in the first place.

All you really need to do is
a) create a procedure with a web client
b) send a POST to the server

Any of the web client examples will help you get the construct of the POST right, but with a slight twist since you are sending a file. So here's the basic Post without a file;

  ! set header properties here, see examples
  net.AddValue('fieldname','c:\filenametosend',true)
  net.Post('http://www.capesoft.com/somepage')

By not passing a "post string" to the Post method, the values are all taken care of for you. in this case there's a single value, the form field name is the first parameter, the second is the name of the file on your PC and the third is true.

The Post will happen asynchronously so your client procedure should wait for the .Done method, or .ErrorTrap method to be called before closing.

Cheers
Bruce

David

  • Full Member
  • ***
  • Posts: 127
    • View Profile
Re: NetWebClient - Uploading a file to a NetWebServer
« Reply #2 on: October 24, 2010, 08:51:49 AM »
Thank you Bruce,

After reading your post and playing with the example app, I was able to post a file to my web server very easily.

ThisWebClient.SetAllHeadersDefault()
ThisWebClient.CanUseProxy = TRUE
ThisWebClient.HeaderOnly = FALSE

ThisWebClient.AsyncOpenUse = TRUE ! Use AsyncOpen 12 seconds (recommended)
ThisWebClient.AsyncOpenTimeOut = 1200 ! Up to 12 seconds to connect

ThisWebClient.InActiveTimeout = 9000 ! Set IdleTimeout 90 seconds

ThisWebClient.SSLCertificateOptions.CertificateFile = ''
ThisWebClient.SSLCertificateOptions.PrivateKeyFile = ''
ThisWebClient.SSLCertificateOptions.DontVerifyRemoteCertificateCommonName = TRUE
ThisWebClient.SSLCertificateOptions.DontVerifyRemoteCertificateWithCARoot = TRUE

ThisWebClient.OptionAutoCookie = 1
ThisWebClient.SetValue('UploadFile','c:\temp\mytestfile.txt',Net:IsFile)
ThisWebClient.SetValue('pressedButton','save_btn')
   
ThisWebClient.Post('https://localhost', '')