filing out the form to a hidden webpage.
Ok, I need to use http to upload files. I have tried many times with the inet control. But it refuses to work. So I was wondering. How would I go about filing out the form of a form to a hidden webcontrol page?
I need to do it to send data to a linux server for processing and stuff. But I'm new to vb and have to clue how to go about this. An example would be nice also if possable..
Crash course in HTTP Protocol
Your best option is to get low down and dirty with the HTTP Protocol... ;)
If you need to upload form data to an HTTP server, there are two options available: POST and GET.
Post is preferred, as the data isn't stored in the URL as with GET... POST also supports the upload of files... The following examples detail how you would go about uploading form information...
Example of using HTTP GET Method
Code:
'Assumes Form fields named txtName and txtEmail
strData = "GET /Data.cgi?txtName=Digital+X%2DTreme&txtEmail=digital%5Fx%[email protected] HTTP/1.1" & vbCrlf
strData = strData & "ADDITIONAL HTTP HEADER INFO" & vbcrlf & vbcrlf
'Connect to HTTP Server, then send
Winsock.SendData strData
Example using HTTP POST Method
Code:
'Assumes Form fields named txtName and txtEmail
strData = "POST /Data.cgi HTTP/1.1" & vbCrlf
strData = strData & "ADDITIONAL HTTP HEADER INFO" & vbcrlf & vbcrlf
strData = stRData & "txtName=Digital+X%2DTreme&txtEmail=digital%5Fx%[email protected]"
'Connect to HTTP Server, then send
Winsock.SendData strData
Uploading a file i similar, but encoding it in the correct format is trickier. Below is an example of the data that is sent to an HTTP Server when a file is posted... The file is a small text file.
Quote:
POST /upload.cgi HTTP/1.1
Content-Type: multipart/form-data; boundary=---------------------------7d1226321c8
Content-Length: 315
-----------------------------7d1226321c8
Content-Disposition: form-data; name="fileFIELD"; filename="D:\Documents\Hello_World.txt"
Content-Type: text/plain
Hello World!
-----------------------------7d1226321c8--
Anyway, that is the format you would need to send the file upload in to an HTTP server. If you need more help, post back :)
Laterz
a little more info on code operation
I'm also trying to upload a file via http using VB, and the code has been helpful (downloaded from Bloodeye, I think).
I'm trying to send several files to an apache server running Perl, but I appear to be having some problems where the debugger stops at:
Set docinputFile1 = doc.Forms(0).elements(0)
I wasn't sure what references need to be set or other pointers may be necessary. Pls help.
Thanks!