|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Form Upload Test Utility?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! 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! "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. Thanks!> > 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(); 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 :-)
Multi-User Data App Architecture
How to use one datagrid to update/insert into another Migrating to VS 2005 11th hour failure to trigger click event for object in hash table Bring in a form from another solution/project Re: destroying/releasing objects from memory? Connected App (VB2005) Help... convert BASIC to VB.NET How to Insert field and value into another grid Trying to write a COM accessible DLL |
|||||||||||||||||||||||