NetTalk Central
September 05, 2010, 05:49:52 pm *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome to the NetTalk Central Forums!
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Posting a file to a web site  (Read 1662 times)
seanh
Newbie
*
Posts: 2


View Profile Email
« on: October 18, 2007, 09:15:12 pm »

The docs posting for a file only mention this in passing.
For multi part mime message, ie a file, you need to add '--' in front of the boundary string!

Hopefully this will save someone the 2 hours it took me find this.

Here is some code that works:
FileLen = ReadFileToString('WebProducts.csv',FileContents)

WebURL = 'http://' & clip(config:website) & '/admin/au_addproductsupload.php'

PostString = '--' & Boundry & CRLF |
           & 'Content-Disposition: form-data; name="localproductsfile"; filename="WebProducts.csv"' & CRLF |
           & 'Content-Type: application/octet-stream' & CRLF |
           & CRLF |
           & fileContents[1:filelen]    |
           & CRLF |
           & '--' & Boundry & CRLF |
           & 'Content-Disposition: form-data; name="Submit"' & CRLF |
           & CRLF |
           & 'Submit'& CRLF |
           & '--' & Boundry & '--' & CRLF |
           
ThisWebClient.SetAllHeadersDefault() ! We recommend you call this before Fetch()
                          ! You may want to modify some properties after this.
ThisWebClient.CanUseProxy = 1 ! Can use a proxy
ThisWebClient.ProxyServer = 'localhost'          ! Debug
ThisWebClient.ProxyPort = 81                     ! Debug

ThisWebClient.HeaderOnly = 0
!ThisWebClient.Cookie = Cookie
!ThisWebClient.Referer = Referer
ThisWebClient.ContentType = 'multipart/form-data; boundary=' & Boundry
ThisWebClient.AcceptEncoding = ''
ThisWebClient.ContentLength = Len(Clip(PostString))
ThisWebClient.Pragma_ = 'no-cache'

ThisWebClient.AsyncOpenUse = 1 ! Use AsyncOpen 12 seconds (recommended)
ThisWebClient.AsyncOpenTimeOut = 2000 ! up to 12 seconds to connect

ThisWebClient.InActiveTimeout = 9000 ! Set IdleTimeout 90 seconds
!ThisWebClient.Post(WebURL,PostString)
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!