1. Dim hosturl as new system. Uri (http: // 127.0.0.1/C :/..../)
Dim request as httpwebrequest
Dim FS as new filestream (filepath, filemode. Open, fileaccess. Read)
Request = ctype (webrequest. Create (hosturl), httpwebrequest)
Request. Timeout = 1000*5*60
Request. method = "Post"
Request. keepalive = true
Request. contentlengh = FS. Length
Dim poststream as stream = request. getrequeststream ()
Dim strdata as string
Dim SR as streamreader = new streamreader (path, false)
Dim swsaveto as streamwriter = new streamwriter (path, false)
Dim by (1024) as byte
Dim N as integer
N = FS. Read (by, 0, by. length)
Strdata = Sr. Readline ()
Do while n> 0
Swsaveto. writeline (strdata, poststream)
N = FS. Read (by, 0, by. length)
Loop
FS. Flush ()
FS. Close ()
Sr. Close ()
Swsaveto. Close ()
----------------------------------------
'upload file
Public Function uploadthefile (byval uploadurl as string, byval uploadfilename as string) as string
dim hosturl as new system. uri (uploadurl)
dim request as system. net. httpwebrequest
dim FS as new system. io. filestream (uploadfilename, filemode. open, fileaccess. read) 'get the data stream of the local file
request = ctype (system. net. webrequest. create (hosturl), system. net. httpwebrequest)
request. timeout = 1000*5*60 'set the timeout value to 30 seconds
request. method = "Post" 'transmission method
request. keepalive = true
request. contentlength = FS. length 'sets the length of the transmitted data.
dim poststream as stream = request. getrequeststream () 'send request
dim B (1024) as byte
dim N as integer
'Write File to server
N = FS. read (B, 0, B. length)
do while n> 0
poststream. write (B, 0, n)
N = FS. read (B, 0, B. length)
loop
FS. flush () 'clear the buffer
FS. close ()
'the above post information to the server.
'The following is the server response information.
Dim response as system. net. httpwebresponse = ctype (request. getresponse (), system. net. httpwebresponse)
Dim restream as streamreader = new streamreader (response. getresponsestream,
System. Text. encoding. getencoding ("gb2312 "))
Dim resstr as string = restream. readtoend ()
Msgbox (response. statuscode. tostring) 'status code returned after posting to the network server. If it succeeds, "OK" is returned"
Response. Close () 'Close
End Fu
This article from csdn blog: http://blog.csdn.net/ITshu/archive/2009/02/27/3943149.aspx