473,769 Members | 5,374 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.WebC lient
Dim body As String
Const boundary as String = "xz9xBzBYzZ Y"
FileName = "ABC.PDF"

' Read file contents into Byte Array
Dim st As New FileStream(File Name, FileMode.Open)
Dim FileBytes() As Byte
ReDim FileBytes(st.Le ngth)
st.Read(FileByt es, 0, st.Length)
st.Close()

myWebClient.Hea ders.Add("Accep t", "image/gif, image/x-xbitmap, image/jpeg,
image/pjpeg, */*")
myWebClient.Hea ders.Add("Refer er", "")
myWebClient.Hea ders.Add("Accep t-Language", "en-us")
myWebClient.Hea ders.Add("Conte nt-Transfer-Encoding",
"applicatio n/octet-stream")
myWebClient.Hea ders.Add("Conte nt-Type", "multipart/form-data; boundary=" &
boundary)
myWebClient.Hea ders.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.Hea ders.Add("Cache-Control", "no-cache")
myWebClient.Hea ders.Add("Cooki e", "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.defaul t.GetBytes(body )
Dim byteBodyArray2 As Byte()
byteBodyArray2 = Encoding.defaul t.GetBytes(body 2)

Dim ByteArrayToSend () As Byte
ReDim ByteArrayToSend (byteBodyArray. Length + FileBytes.Lengt h +
byteBodyArray2. Length)
byteBodyArray.C opyTo(ByteArray ToSend, 0)
FileBytes.CopyT o(ByteArrayToSe nd, byteBodyArray.L ength - 1)
byteBodyArray2. CopyTo(ByteArra yToSend, byteBodyArray.L ength +
FileBytes.lengt h - 2)

Dim bResponseArray As Byte() = myWebClient.Upl oadData(PostURL , "POST",
ByteArrayToSend )

End Sub
--------
Nov 19 '05 #1
3 2910
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.Uploa dFile() 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.d e
Nov 19 '05 #4

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

Similar topics

0
1309
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 machines are on different domains client state is SYN_SENT (and not ESTABLISHED as expected). This problem does not arise if we use sockets. Is this a problem with WebClient class or is it some networking issue(firewall etc)? Thanks,
4
10320
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: http://www.someURL.com?parm1=data1&parm2=data2. I don't believe these paramters are transmitted as part of the URL with the HTTP Post interface. I was under the impression that the WebClient class automatically handled these parameters for POST. The...
3
7588
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 a form and the values, test.asp reports them fine. ---------------------------- Dim thePost As String = "Variable1=Value1&Variable2=Value2&Variable3=Value3" Dim thePage As Byte() Dim MyWebClient As New System.Net.WebClient
0
1438
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 development and 1 for a staging environment. I'm using an invalid servlet name in the url deliberately in order to test my logic for basic communication problems. When I run the code against the staging box, I get a 5xx error back, which is what I...
3
1963
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 problem that if we run it multiple times in a short time span something fails. ANd I was wondering if the webclient could be the cause of problems.
1
1762
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 how to send a form and send the client to the external url at the same time. Can anyone help? 'Step 1 create form data Dim formPostData As String = String.Empty formPostData &= "AmountPaid=" & Booking.AmountPaid
4
7783
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. The problem is, certain cookies need to be set, and the only way of doing that is not letting the WebClient automatically go on to the next GET in the background--I need to do it manually. I'm wondering if this has something to do with the...
2
3965
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 access an ebay page. There is no redirection involved in TestPage. If you have an ebay account you can try it in 1 minute. What's wrong with my code?
0
2367
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 (Please refer to the figure below for better understanding). http://img100.imageshack.us/img100/8720/iis.th.jpg After that, I edit the photo's directory security by clearing up the anonymous access checkbox and check/tick the Integrated Windows...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3564
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.