Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTTP POST to Upload Binary, PDF, etc

Status
Not open for further replies.

ClarkJeff

Programmer
Feb 28, 2002
46
0
0
US
Anyone have any ideas on how to post PDF and binary files on a server to another server via a HTTP POST? I've been searching the web and have found some examples, but I can't seem to get them to work properly. I'm using Dundas' free upload component on the receiving server. I suspect it's something in my binary->string conversion, as I'm receiving an error that the Upload was not finished correctly. Looking at the header shows me that the Content-Length is not correct, but I can't override that either. I'm not loyal to this exact code, so any suggestions/code sample would be greatly appreciated!

Thanks!

...
Dim objHttp As XMLHTTP30
...

strBody = "--" & conststrBoundary & vbCrLf & "Content-Disposition: form-data; name=""FileName""" & vbCrLf & vbCrLf & strFileName & vbCrLf

strBody = strBody & "--" & conststrBoundary & vbCrLf & "Content-Disposition: form-data; name=""File1""; filename=""" & strFileName & """" & vbCrLf

strBody = strBody & "Content-Type: application/upload" & vbCrLf & vbCrLf

lngIndex = FreeFile

Open strFileName For Binary As lngIndex

ReDim aryBody(objFSO.GetFile(strFileName).Size - 1)

Get lngIndex, 1, aryBody

Close lngIndex

strBody = strBody & StrConv(aryBody, vbUnicode)

strBody = strBody & vbCrLf & "--" & conststrBoundary & "--"

objHttp.send strBody
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top