Home All Groups Group Topic Archive Search About

Form Upload Test Utility?

Author
12 Dec 2006 5:06 AM
Spam Catcher
Anyone know of any form upload utilities which will allow me to upload
files to an ASP.NET page without the need of a web browser?

I like to test a form upload page I wrote (no GUI, it only accepts a form
post).

Thanks!

Author
12 Dec 2006 9:14 AM
Steve B.
You can use the HttpWebRequest class.

use something like this (from my memory) :

HttpWebRequest req =
(HttpWebRequest)WebRequest.CreateDefault(http://youpage);

Stream s = req.GetResquestStream();

byte[] post = Encoding.ASCII.GetBytes(string.format(
"yourpostvar={0}&yourotherpostvar={1}",
HttpUtility.UrlEncode("The value of your post variable"),
5.ToString()
);

s.Write(raw, 0, raw.Length);
s.Close();

HttpWebResponse resp = req.GetResponse();

Stream respStream = resp.GetResponseStream();

StreamReader sr = new StreamReader(respStream);

return sr.ReadToEnd();


Notice the post variables are string in ASCII encoding. If you require
passing value that are strings, you will have to deal with string
convertion. Use classic .ToString() and .Parse() methods for simple types,
and Convert.ToBase64String() and Convert.FromBase64String() to handle byte
array (which can for example a byte representation of a serialized object in
binary format, or even xml format).
The other issue I met concerned the international chars like éàç. I needed
to encode it into a byte array then passing it in base 64 form, even if the
type was in string format (but there's certainly better ways).

Hope that helps
Steve


"Spam Catcher" <spamhoneypot@rogers.com> a écrit dans le message de news:
Xns989712D077E2usenethoneypotrogers@127.0.0.1...
Show quoteHide quote
> Anyone know of any form upload utilities which will allow me to upload
> files to an ASP.NET page without the need of a web browser?
>
> I like to test a form upload page I wrote (no GUI, it only accepts a form
> post).
>
> Thanks!
Author
12 Dec 2006 3:33 PM
Spam Catcher
"Steve B." <steve_beauge@com.msn_swap_msn_and_com> wrote in news:u
$Mn03cHHHA.1***@TK2MSFTNGP04.phx.gbl:

Show quoteHide quote
> You can use the HttpWebRequest class.
>
> use something like this (from my memory) :
>
> HttpWebRequest req =
> (HttpWebRequest)WebRequest.CreateDefault(http://youpage);
>
> Stream s = req.GetResquestStream();
>
> byte[] post = Encoding.ASCII.GetBytes(string.format(
> "yourpostvar={0}&yourotherpostvar={1}",
> HttpUtility.UrlEncode("The value of your post variable"),
> 5.ToString()
> );
>
> s.Write(raw, 0, raw.Length);
> s.Close();
>
> HttpWebResponse resp = req.GetResponse();
>
> Stream respStream = resp.GetResponseStream();
>
> StreamReader sr = new StreamReader(respStream);
>
> return sr.ReadToEnd();

Thanks!

I found an easier way - I just whipped up a HTML page and made the form
post directly to my ASPX test page.

Duh - don't know why I didn't think of that in the first place :-)