473,383 Members | 1,868 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Weird WebClient UploadData Problem

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
--------
Nov 19 '05 #1
3 2877
snt
My assumption is that this is something to do with your browser.

snt
http://www.flexoweb.com
http://www.onlinemall.com

Nov 19 '05 #2
Yeah - thats what I initially thought but it happens with anyone using IE.
I've tried it with many people.

"snt" wrote:
My assumption is that this is something to do with your browser.

snt
http://www.flexoweb.com
http://www.onlinemall.com

Nov 19 '05 #3
bss2004 wrote:
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!


Two notes:

1. There's no HTTP header Content-Transfer-Encoding. What you want is
"Content-Type".

2. WebClient.UploadFile() does exactly what you're trying to achieve
(although there's a bug in pre .NET 2.0 implementations). Did you try
it?

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ramkrishna Kulkarni | last post by:
Hi, We are using UploadData method of WebClient class in C# to establish connection(s) between two machines(typical client/server). Connection is established if the machines are on same domain. If...
4
by: Paul J. Lay | last post by:
I am sending and receiving multipart messages using the WebClient UploadData method Method=Post. Everything seems to work well except when the URL contains parameters. For example:...
3
by: Manuel | last post by:
I have an asp page ("test.asp") that presents the data it receives from a post.When I try the following code, test.asp doesn't return the values (supposedly) posted to it. If I make a web page with...
0
by: Mark | last post by:
I have a very strange problem that is driving me nuts. My application is using the webclient object to send data to a webserver running on a unix box. We use 2 different environments, 1 for...
3
by: Philip Wagenaar | last post by:
Hello, I have a executeble that sends a request to a webserver: Return Encoding.UTF8.GetString(myWebClient.UploadData(uri, "POST", Encoding.UTF8.GetBytes(postString))) We are a having a...
1
by: Rippo | last post by:
Hi I need to post a form to an external URL, get a repsonse, then repost to an external URL and redirect at the same time. I can figure out step 1 and step 2 fine but I cant seem to figure out...
4
by: Lehel Kovach | last post by:
I'm having a problem with the WebClient object. When I post data to certain sites, it will receive a command from the webserver (object moved) and continue to the next link by downloading that. ...
2
by: Tosco | last post by:
I read many examples with NetworkCredential and WebClient, but no one with a real http address. They all work in theory, but I wasn't able to use them in the real world. The following code should...
0
by: y2ktan | last post by:
Hi All, I try to use WebClient.UploadData to upload a photo with the size less than 1MB to my local IIS. I setup my IIS by adding a new virtual directory with the write access to the photo...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.