开发者

How do I HTTP-POST a JPG in Windows Phone Silverlight?

I'm trying to build JPG upload functionality into our Windows Phone app.

The server-side is complete; I have a REST API already built that accepts a st开发者_如何学Pythonandard JPG via HTTP POST and saves it to the server. I can successfully post to this from a FORM in html.

However, after two days of trying various approaches, I still cannot figure out how to craft the C# code that builds this HTTP POST using either HttpWebRequest or WebClient. (Note, while I like WCF, and know it can do REST, I would prefer not to use WCF on the server for consistency's sake with other code.)

I would love to see how to generate a fully compliant HTTP POST, complete with JPG writing, posting up something that can be read by Request.Files[] on the server. I'd post what I've tried, but I think it'd only add to the confusion -- frankly, it's kind of a mess at this stage, and I'm sure the solution is simpler.

I have seen various threads here on StackOverflow and other sites discussing general approaches, but despite these helpful responses, they are incomplete, or not applicable to the WinPhone subset. (Note that UploadFile is not available in the Windows Phone subset of Silverlight, for instance.)

Among other things, I haven't figured out how to convert a JPG to a byte array to write on the stream. Can anyone help me with a fully working code sample of a client sending up a single JPG in an HTTP POST?


The easiest solution I've found is to use the Windows Phone POST client


You can find solutions to this at:

Uploading an image using C# and WebRequest?
and
Upload files with HTTPWebrequest (multipart/form-data)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜