Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / March 2005

Tip: Looking for answers? Try searching our database.

posting base64 data using http post

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jonathan Eggert - 24 Mar 2005 01:40 GMT
What I'm looking for is how to send a file to a web service in Base64 format, using Http Post. I know this can be done using SOAP, but I'd like to know how to do this using Http Post.

My thinking was to use HttpWebRequest something along the lines of the code listed below.

protected Byte[] data;

//  logic to stream the file to the byte array
//  goes here

//  post file to service
string postData = "file=" + HttpUtility.UrlEncode(data,0,filelength) +
"&name=" + HttpUtility.UrlEncode("image.jpg");

           
UTF8Encoding encoding = new UTF8Encoding();
byte[] buffer = encoding.GetBytes(postData);
       

string _webServiceURI="http://localhost/webservice.asmx";
           string _webMethodName="Upload";
           string uri = _webServiceURI + "/" + _webMethodName;

           HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(uri);
           httpRequest.Method = "POST";
           httpRequest.KeepAlive = false;
           httpRequest.ContentType = "application/x-www-form-urlencoded";
           httpRequest.ContentLength = buffer.Length;
           httpRequest.Timeout = 30000;
           httpRequest.GetRequestStream().Write(buffer, 0, byte1.Length);
           httpRequest.GetRequestStream().Close();

This is the stub for the web service :

[WebMethod (MessageName="Upload")]
public string  Upload(Byte[] file, string name)
{

}
Joerg Jooss - 25 Mar 2005 11:35 GMT
> What I'm looking for is how to send a file to a web service in Base64
> format, using Http Post. I know this can be done using SOAP, but I'd
[quoted text clipped - 38 lines]
>
> }

You're doing some weird things here...

You cannot encode binary content using a character encoding. If you
want to use base64, why don't you use it, e.g. Convert.ToBase64String()?

Since you're not posting a web form, the content-type
application/x-www-form-urlencoded does not apply. Use
application/soap+xml, text/xml, or whatever the server-side accepts.

Cheers,
Signature

http://www.joergjooss.de
mailto:news-reply@joergjooss.de


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.