So I fought and fought with this, ultimately going back to one of the sample scripts I was given. Here's where I ended up with (two read variables, one write variable):
Public Sub Main()
Dim FilePathName As String = Dts.Variables.Item("InboundPathAndName").Value
Dim url As System.Uri
Dim webReq As HttpWebRequest
Try
url = New System.Uri(Dts.Variables.Item("HttpPostURL").Value.ToString)
webReq = CType(WebRequest.Create(url), HttpWebRequest)
'POST Data
webReq.Method = "POST"
webReq.ContentType = "multipart/form-data; boundary=xyz"
webReq.Headers.Add("Cookie", "SMCHALLENGE=YES")
' convert username:password to basic 64 format and append to the HTTP
' header
webReq.Headers.Add("Authorization", _
Dts.Variables.Item("HttpAuth").Value.ToString)
webReq.KeepAlive = True
Dim dataBoundary As String = "------xyz"
Dim endingBoundary As Byte() = _
System.Text.Encoding.Default.GetBytes(vbCrLf + "------xyz--" + vbCrLf)
Dim ReadIn As FileStream
Dim tempStream As Stream
'create the information we need to send as part of post to let
'the ASPX page know about the file data
Dim DataString As StringBuilder = New StringBuilder
DataString.Append(dataBoundary + vbCrLf)
DataString.Append("Content-Disposition: form-data; name=" + _
"""" + "file" + """" + "; filename=" + """" + _
FilePathName.ToString + """" + vbCrLf)
'set the file type to octet-stream so we can handle any kind of Data()
DataString.Append("Content-Type: application/octet-stream" + _
vbCrLf + vbCrLf)
'open the file to post
ReadIn = New FileStream(FilePathName, FileMode.Open, FileAccess.Read)
ReadIn.Seek(0, SeekOrigin.Begin) 'move to the start of the file
Dim FileData(1024) As Byte 'read the file in 1k chunks
Dim DataRead As Integer = 0
tempStream = webReq.GetRequestStream()
'send the data about the file
Dim FileInfo As Byte() = _
System.Text.Encoding.Default.GetBytes(DataString.ToString())
tempStream.Write(FileInfo, 0, FileInfo.Length)
Do
DataRead = ReadIn.Read(FileData, 0, 1024)
If (DataRead > 0) Then 'we have data
tempStream.Write(FileData, 0, DataRead)
Array.Clear(FileData, 0, 1024) 'clear the array
End If
Loop While (DataRead > 0)
' send the closing boundry
tempStream.Write(endingBoundary, 0, endingBoundary.Length)
'close the stream
ReadIn.Close()
tempStream.Close()
'Get the response from the server
Dim webResp As HttpWebResponse = webReq.GetResponse()
Dim sr As New StreamReader(webResp.GetResponseStream())
'put the stream data in a string
Dim respData As String = sr.ReadToEnd()
sr.Close()
webResp.Close()
'MessageBox.Show(respData) 'Troubleshoot response
Dts.Variables.Item("WebsiteResponse").Value = respData.ToString
Catch webExcp As WebException
'If you reach this point, an exception has been caught.
'Write out the WebException message.
MessageBox.Show("An error occured." + webExcp.ToString())
Return
Catch myExcp As Exception
MessageBox.Show("A WebException has been caught." + myExcp.ToString())
Return
End Try
Dts.TaskResult = ScriptResults.Success
End Sub
End Class
Just a note. When I tried getting rid of the 1 KB chunk process, the whole script blew up telling me the data was too large to read. So I added it back in. I'm not sure if the "too big" came from BIDS or the website, but I now know that I need it in this specific instance.
EDIT: Thanks everyone for all your assistance. It was very valuable.