473,385 Members | 1,838 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,385 software developers and data experts.

Issue with HttpWebRequest & multipart/form-data

Du
I'm trying to automate the upload process to yousendit.com, but the file
size doesn't add up and yousendit.com keep rejecting my upload (it accepts
the upload until the very end)

I don't know what i'm missing, I use Fiddler and I got my header and body to
a very close match, but the content-length is slightly off and I got no clue
why

Sorry for the lengthy post, but i have no other way of showing my work

Can someone please explain the difference in content-length, I can't seem to
work it out. I been searching on google and the news group, but i got
nothing.
Thanks for any input


// =======My Request Header==========

Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword,
application/x-shockwave-flash, */*
Referer: http://s12.yousendit.com/
Content-Type: multipart/form-data;
boundary=---------------------------7d5158213e047e
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
1.1.4322)
Pragma: no-cache
Accept-Languag: en-us
Content-Length: 1766 <--- notice this is only 1766 byte, but the IE
value is 2026
Expect: 100-continue
Proxy-Connection: Keep-Alive
Host: s12.yousendit.com

// ============ My Request Body ======================

---------------------------7d5158213e047e
Content-Disposition: form-data; name="__VIEWSTATE"

dDwtMTgyNzA1MTg5OztsPFVwbG9hZEZpbGU7Pj6IqrAZhsvVRc 9Qe1y6cNu6G3V3nQ==
---------------------------7d5158213e047e
Content-Disposition: form-data; name="ToEMail"

mi*******@yahoo.com
---------------------------7d5158213e047e
Content-Disposition: form-data; name="LoadFileName";
filename="D:\Desktop\encoder_check.zip"
Content-Type: application/octet-stream

PK



Same file but using internet explorer to upload
// ========== request header ==========
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword,
application/x-shockwave-flash, */*
Accept-Language: en-us
Content-Type: multipart/form-data;
boundary=---------------------------7d533333730406
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
1.1.4322)
Host: s12.yousendit.com
Content-Length: 2026
Proxy-Connection: Keep-Alive
Pragma: no-cache
// =========== request body ===============
-----------------------------7d533333730406
Content-Disposition: form-data; name="__VIEWSTATE"

dDwtMTgyNzA1MTg5OztsPFVwbG9hZEZpbGU7Pj6IqrAZhsvVRc 9Qe1y6cNu6G3V3nQ==
-----------------------------7d533333730406
Content-Disposition: form-data; name="ToEMail"

mi*******@yahoo.com
-----------------------------7d533333730406
Content-Disposition: form-data; name="LoadFileName";
filename="D:\Desktop\encoder_check.zip"
Content-Type: application/x-zip-compressed

PK

// ============ My Code ==============
string url = @"http://s12.yousendit.com/default.uplx";

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

req.Method = "POST";

req.Accept = @"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword,
application/x-shockwave-flash, */*";

req.Referer = @"http://s12.yousendit.com/";

req.ContentType = @"multipart/form-data;
boundary=---------------------------7d5158213e047e";

req.UserAgent = @"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;
..NET CLR 1.1.4322)";

req.KeepAlive = true;

req.Headers.Add("Pragma", "no-cache");

req.Headers.Add("Accept-Languag", "en-us");

req.Timeout = Timeout.Infinite;
string payload =
"---------------------------7d5158213e047e\r\nContent-Disposition:
form-data;
name=\"__VIEWSTATE\"\r\n\r\ndDwtMTgyNzA1MTg5OztsPF VwbG9hZEZpbGU7Pj6IqrAZhsvVRc9Qe1y6cNu6G3V3nQ==\r\n---------------------------7d5158213e047e\r\nContent-Disposition:
form-data; name=\"ToEMail\"\r\n\r\n" + txtEmail.Text +
"\r\n---------------------------7d5158213e047e\r\nContent-Disposition:
form-data; name=\"LoadFileName\"; filename=\"" + filename +
"\"\r\nContent-Type: " + getMimeType(filename) + "\r\n\r\n";

FileInfo file = new FileInfo(filename);

int filesize = Convert.ToInt32(file.Length);
req.ContentLength = payload.Length + file.Length;

// ==================== Start writing ====================

Stream conn = req.GetRequestStream();
byte[] body_header = System.Text.Encoding.ASCII.GetBytes(payload);

conn.Write(body_header, 0, body_header.Length);

FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);

byte[] file_content = new byte[filesize];

int len = fs.Read(file_content, 0, filesize);

conn.Write(file_content, 0, len);

fs.Close();
Stream respon = req.GetResponse().GetResponseStream();

StreamReader sr = new StreamReader(respon);

extractsendItLink(sr.ReadToEnd());

sr.Close();

respon.Close();
conn.Close();
Nov 17 '05 #1
8 12199
Du wrote:
I'm trying to automate the upload process to yousendit.com, but the
file size doesn't add up and yousendit.com keep rejecting my upload
(it accepts the upload until the very end)

I don't know what i'm missing, I use Fiddler and I got my header and
body to a very close match, but the content-length is slightly off
and I got no clue why

Sorry for the lengthy post, but i have no other way of showing my work

Can someone please explain the difference in content-length, I can't
seem to work it out. I been searching on google and the news group,
but i got nothing.


Check again with Fiddler. As far as I can see, you're at least missing
the final boundary:
---------------------------7d5158213e047e--

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 17 '05 #2
Du
I added the end boundary and still no go

any other though???

thanks

"Joerg Jooss" <ne********@joergjooss.de> wrote in message
news:xn****************@msnews.microsoft.com...
Du wrote:
I'm trying to automate the upload process to yousendit.com, but the
file size doesn't add up and yousendit.com keep rejecting my upload
(it accepts the upload until the very end)

I don't know what i'm missing, I use Fiddler and I got my header and
body to a very close match, but the content-length is slightly off
and I got no clue why

Sorry for the lengthy post, but i have no other way of showing my work

Can someone please explain the difference in content-length, I can't
seem to work it out. I been searching on google and the news group,
but i got nothing.


Check again with Fiddler. As far as I can see, you're at least missing
the final boundary:
---------------------------7d5158213e047e--

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de

Nov 17 '05 #3
Du wrote:
I added the end boundary and still no go

any other though???


Character encoding? You're using ASCII, but I bet IE isn't. This will
only be relevant if you post non-US-ASCII characters though. Is this
the case?

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 17 '05 #4
Du wrote:
I added the end boundary and still no go

any other though???


Character encoding? You're using ASCII, but I bet IE isn't. This will
only be relevant if you post non-US-ASCII characters though. Is this
the case?

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 17 '05 #5
Du
nope, it's all ascii, I also try utf-8 .. but still the same problem

Thanks Jooss, I really appreciate this
"Joerg Jooss" <ne********@joergjooss.de> wrote in message
news:xn****************@msnews.microsoft.com...
Du wrote:
I added the end boundary and still no go

any other though???


Character encoding? You're using ASCII, but I bet IE isn't. This will
only be relevant if you post non-US-ASCII characters though. Is this
the case?

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de

Nov 17 '05 #6
Du
nope, it's all ascii, I also try utf-8 .. but still the same problem

Thanks Jooss, I really appreciate this
"Joerg Jooss" <ne********@joergjooss.de> wrote in message
news:xn****************@msnews.microsoft.com...
Du wrote:
I added the end boundary and still no go

any other though???


Character encoding? You're using ASCII, but I bet IE isn't. This will
only be relevant if you post non-US-ASCII characters though. Is this
the case?

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de

Nov 17 '05 #7
Du wrote:
nope, it's all ascii, I also try utf-8 .. but still the same problem


Hm... did you post your entire code in your first post? We must be
missing something here.

Cheers,

--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 17 '05 #8
Du wrote:
nope, it's all ascii, I also try utf-8 .. but still the same problem


Hm... did you post your entire code in your first post? We must be
missing something here.

Cheers,

--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 17 '05 #9

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

Similar topics

4
by: John Fereira | last post by:
So, one of the limitations of multipart-form handling is that when an <input type="file" ..> tag is used it will bring up a window which allows a user to select a file for upload but won't allow...
2
by: Mark Rae | last post by:
Hi, Can anyone please tell me if it's possible to use HttpWebRequest and HttpWebResponse in a class in a Windows application? I've tried referencing System and System.Web but there's still...
0
by: Pmcg | last post by:
I would appreciate any help with the following, havn't found any answers for this in my research to date. I am trying to retreive a web page (a htm file intially) from a vdir on an intranet site...
3
by: Li Zhang | last post by:
I know I can use controlName.Value to retrieve the form fields value if I am in that page. But if I am out of the page, for example I am in a HttpModule, I want to retrieve a hidden filed value, Is...
0
by: Brent | last post by:
I'm hoping to grab some 70,000 text files over http using the code below. For the most part, the files are a few KB in size, and are downloaded quickly. The code meets its Waterloo, however, with a...
16
by: Cheung, Jeffrey Jing-Yen | last post by:
I have a windows form application that generates a request, downloads an image, and waits the user to enter in login info. Unfortunately, this image is dynamic and based on session data. I have...
15
by: Snedker | last post by:
I'm using (HttpWebRequest and HttpWebResponse to check for updates. But how do I determine the size of the file before download? What I have in mind is a status text like "You have downloaded...
2
by: Greg | last post by:
I've been reading a lot of other posts and trying a bunch of things but just cannot get this to work. I'm hoping someone can help. Here's the situation. I have a test folder which only...
2
by: Greg | last post by:
I've been reading a lot of other posts and trying a bunch of things but just cannot get this to work. I'm hoping someone can help. Here's the situation. I have a test folder which only...
4
by: DMG | last post by:
I have <identity impersonate = "true" /& <authentication mode="Windows"/in the web.config. This is a 2.0 site. My Goal: I want to simply have the user browse to a file on a mapped drive and get...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.