demaxSH
demaxSH

Reputation: 1815

How to use WebClient.UploadStringAsync to upload byte array?

I have a working example of webClient.UploadDataAsync(Uri addr, string method, byte[] data) in WPF, it calls a RESTful api and works well.

Now I want to call the same RESTapi in silverlight, unfortunately WebClient in Silverlight only has the method of webClient.UploadStringAsync(Uri addr, string method, string data) How can I pass the byte array as a string parameter?

Upvotes: 1

Views: 2170

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564413

In Silverlight, the way to upload binary data is via WebClient.OpenWriteAsync. This asynchronously opens a writable stream, which can then be used to upload the file (in the event handler).

For a full sample, including code, see this post.

Upvotes: 1

Related Questions