Thoughts from Dan Miser RSS 2.0
# Tuesday, May 30, 2006
I've been writing a .NET client application that must upload a file to a IBM WebSphere (Java) server. This journey was met with mis-steps all over the place. For starters, it looked like the WebClient class was what I wanted, but it turns out you can't POST both a file and HTML form variables. That meant that I needed to go to the low-level class, HttpWebRequest, to get this done. There is code on google that got me most of the way there, but the web server always ended up rejecting the submission with errors. To make matters worse, I don't own the web server, so support on exactly what was wrong was extremely limited.

Then I stumbled across a paper, Retrieving HTTP content in .NET by Rick Strahl. In that paper, Rick ends up writing a very nice wrapper class to deal with all of the details for you. I put together a test case to try this out, and the amount of code I had to write dropped from 123 lines down to 15. The new code even works with WebSphere. What's more, the wrapper class provides a very nice model for programming applications that need to communicate via HTTP. In my opinion, this is what Microsoft should have delivered with the framework, as opposed to making people write their own wrapper or find Rick's code (which was last updated in 2002, yet still works great).

I made 2 changes to Rick's base class:

  • I changed the cMultiPartBoundary variable to look like this in order to give a unique boundary marker: string cMultiPartBoundary = "-----------------------------" + DateTime.Now.Ticks.ToString("x");
  • In the method GetUrlStream, there is a place where the end boundary marker is written to the stream. However, according to the RFC on uploading files via POST, you need to have 2 trailing dashes to mark the last end. I added those dashes like this: this.oPostData.Write(Encoding.GetEncoding(1252).GetBytes( "--" + this.cMultiPartBoundary + "--\r\n" ) );

I am one happy camper. I've done this very thing with other web applications in Delphi before, and with the Indy components, it was very easy. Now with Rick's wrapper class, it's easy to do the same kind of thing in .NET.

Tuesday, May 30, 2006 6:32:00 PM (GMT Daylight Time, UTC+01:00)  #    Comments [4] -
Delphi
Tracked by:
http://9nf-information.info/87685793/definition-of-business-forcasting.html [Pingback]
http://9nd-information.info/97607867/index.html [Pingback]
http://9nl-information.info/54933105/index.html [Pingback]
http://9ne-information.info/60464067/index.html [Pingback]
http://9nt-information.info/54058405/index.html [Pingback]
http://9ni-information.info/23776761/index.html [Pingback]
http://9np-information.info/41977526/apartment-guide-wash-an-oregon.html [Pingback]
http://9nm-information.info/95021500/index.html [Pingback]
http://9ni-information.info/45478035/computer-stores-in-toronto-ontario.html [Pingback]
http://9nk-information.info/05144620/cfream-of-broccoli-soup-recipes.html [Pingback]
http://9nn-information.info/07670927/history-of-the-hummer-car.html [Pingback]
http://9om-information.info/12546005/index.html [Pingback]
http://9ou-information.info/52733371/index.html [Pingback]
http://9oo-information.info/17869044/aquarium-corals-company.html [Pingback]
http://9ot-information.info/99561605/homer-simpson-burger-king-song.html [Pingback]
http://9qh-information.info/99415787/hotel-salice.html [Pingback]
http://9ow-information.info/33195451/index.html [Pingback]
http://9oo-information.info/30866300/time-for-college-work-.html [Pingback]
http://9rn-information.info/03749363/index.html [Pingback]
http://9rb-information.info/98387893/index.html [Pingback]
http://9sj-information.info/76958119/progetto-pavimentazione-granito.html [Pingback]
http://9rs-information.info/64074877/index.html [Pingback]
http://9rc-information.info/19147155/index.html [Pingback]
http://9ro-information.info/59238215/index.html [Pingback]
http://9uafl-le-informazioni.info/54949053/index.html [Pingback]
http://9uafh-le-informazioni.info/62125697/h_ospedale-htm.html [Pingback]
http://9uafs-le-informazioni.info/77206045/sammlung-goetz.html [Pingback]
http://9uafs-le-informazioni.info/00951618/boston-marriott-long-wharf.html [Pingback]
http://9uafo-le-informazioni.info/44498675/index.html [Pingback]
http://9uafg-le-informazioni.info/07415617/giacomo-leopardi-zibaldone.html [Pingback]
http://9uaet-le-informazioni.info/31653576/index.html [Pingback]
http://9uaen-le-informazioni.info/74193309/min-cd.html [Pingback]
http://9uafs-le-informazioni.info/19808543/index.html [Pingback]
http://9uahi-le-informazioni.info/44436439/pinnacle-deluxe-studio-9.html [Pingback]
http://9uagg-le-informazioni.info/00156703/fotografia-cazzo-piccolo.html [Pingback]
http://9uagf-le-informazioni.info/46499677/transaminasi-alti.html [Pingback]
http://9uage-le-informazioni.info/47520482/index.html [Pingback]
http://9uaht-le-informazioni.info/62350232/index.html [Pingback]
http://9uagb-le-informazioni.info/67647628/usa-visa-requirement.html [Pingback]
http://9uagt-le-informazioni.info/35972742/risiko-digital-id-prodotto.html [Pingback]
Navigation
Archive
<October 2014>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2014
Dan Miser
Sign In
Statistics
Total Posts: 388
This Year: 0
This Month: 0
This Week: 0
Comments: 630
Themes
Pick a theme:
All Content © 2014, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)