Help!
I'm posting a PDF Doc to a remote server using WebClient UploadData and the
following code. The DOC posts fine and the server returns a positive
response. If I access the remote file in Firefox the Adobe PDF Reader in
Firefox kicks off and I can view the file just fine. HOWEVER, if I try to
access the file using Internet Explorer Adobe never kicks off and I receive a
screenfull of text (which looks like the raw text data of the PDF). This
same behavior is seen by anyone accessing the document (so its not a browser
issue on my side). It must be something that I'm not posting correctly -
like the Content-Transfer-Encoding. But for the life of me I can't figure it
out. Any help would be greatly appreciated!
Thanks a bunch!
This is the code:
--------
Sub SendFile
Dim myWebClient As New System.Net.WebClient
Dim body As String
Const boundary as String = "xz9xBzBYzZY"
FileName = "ABC.PDF"
' Read file contents into Byte Array
Dim st As New FileStream(FileName, FileMode.Open)
Dim FileBytes() As Byte
ReDim FileBytes(st.Length)
st.Read(FileBytes, 0, st.Length)
st.Close()
myWebClient.Headers.Add("Accept", "image/gif, image/x-xbitmap, image/jpeg,
image/pjpeg, */*")
myWebClient.Headers.Add("Referer", "")
myWebClient.Headers.Add("Accept-Language", "en-us")
myWebClient.Headers.Add("Content-Transfer-Encoding",
"application/octet-stream")
myWebClient.Headers.Add("Content-Type", "multipart/form-data; boundary=" &
boundary)
myWebClient.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE
6.0;Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)")
myWebClient.Headers.Add("Cache-Control", "no-cache")
myWebClient.Headers.Add("Cookie", "KEY=" & SomeCookie)
' Create Body
body = ""
body = body & "--" & boundary & vbCrLf
body = body & "Content-Transfer-Encoding: binary" & vbCrLf
body = body & "Content-Disposition: form-data; name=""file_1""; filename="""
& FileName & """" & vbCrLf
body = body & "Content-type: application/pdf" & vbCrLf & vbCrLf
dim body2 as String
body2 = "--" & boundary & "--" & vbCrLf
Dim byteBodyArray As Byte()
byteBodyArray = Encoding.default.GetBytes(body)
Dim byteBodyArray2 As Byte()
byteBodyArray2 = Encoding.default.GetBytes(body2)
Dim ByteArrayToSend() As Byte
ReDim ByteArrayToSend(byteBodyArray.Length + FileBytes.Length +
byteBodyArray2.Length)
byteBodyArray.CopyTo(ByteArrayToSend, 0)
FileBytes.CopyTo(ByteArrayToSend, byteBodyArray.Length - 1)
byteBodyArray2.CopyTo(ByteArrayToSend, byteBodyArray.Length +
FileBytes.length - 2)
Dim bResponseArray As Byte() = myWebClient.UploadData(PostURL, "POST",
ByteArrayToSend)
End Sub
--------