For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic Syntax > April 2005 > Posting a file using HTTP and VB(WININET.DLL).









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Posting a file using HTTP and VB(WININET.DLL).
Sintel Silverblade

2005-03-17, 4:01 pm

I have been working on some code that will do a form post via HTTP and
VB(using WININET.DLL). I can get a normal form post to run however, I can
not get a file post to run. I have search the web mulitiple times and have
yet to get the syntax just right.

Here is the HTML form code I am trying to emulate:

<TR>
<TD valign="top">
Upload file.</TD>
<TD valign="top"><input type="file" name="filename" class="textfield"
SIZE="50" /><br/>
Maximum Filesize is 2 meg<br/>
<input type="hidden" name="MAX_FILE_SIZE" value="204800" /></TD>
</TR>
<TR>
<TD colspan = "2" align ="center">
<INPUT TYPE="SUBMIT" NAME="run" VALUE="Submit" ID="run">
</TD>
</TR>

Here is the code I found on the web dealing with posting a File with
Wininet.dll

sHeader = "Content-Type: multipart/form-data; boundary=913114112" & vbCrLf

lpszPostData = "--913114112" & vbNewLine & "Content-Disposition:" & _
"multipart/form-data; name=""filePath""" & vbNewLine & vbNewLine & _
"This is a test of the input file post" & vbNewLine & "--913114112--"
lPostDataLen = Len(lpszPostData)

bResult = HttpSendRequest(hHttpOpenRequest, _
vbNullString, _
0, _
lpszPostData, _
lPostDataLen)

I am not understanding the lpszPostData section.

Thanks for all your help,

Sintel


Mark Hurd

2005-04-21, 8:59 am

Sintel Silverblade wrote:
> I have been working on some code that will do a form post via HTTP and
> VB(using WININET.DLL). I can get a normal form post to run however, I can
> not get a file post to run. I have search the web mulitiple times and
> have yet to get the syntax just right.
>

<snip>
>
> Here is the code I found on the web dealing with posting a File with
> Wininet.dll
>
> sHeader = "Content-Type: multipart/form-data; boundary=913114112" & vbCrLf
>
> lpszPostData = "--913114112" & vbNewLine & "Content-Disposition:" & _
> "multipart/form-data; name=""filePath""" & vbNewLine & vbNewLine & _
> "This is a test of the input file post" & vbNewLine & "--913114112--"
> lPostDataLen = Len(lpszPostData)
>
> bResult = HttpSendRequest(hHttpOpenRequest, _
> vbNullString, _
> 0, _
> lpszPostData, _
> lPostDataLen)
>
> I am not understanding the lpszPostData section.


If you haven't worked this out yet, it's MIME format -- see the same thing
in email attachments.

Also the code above does not use sHeader. I think it should be

lpszPostData = sHeader & ...

(untested)

--
Regards,
Mark Hurd, B.Sc.(Ma.) (Hons.)

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com