Portable Class Libraries & WebRequest.ContentLength
I have a Portable Class Library that targets ".NET for Windows Store apps" and "Windows Phone 7.5 or higher". I make HTTP POST requests and as of last week, the admins in charge of the back-end decided that I need to send a ContentLength of 0 as opposed to -1 that is defaulted by .NET. I use the WebRequest class but i'm flexible enough to use HttpWebRequest if needed.
Normally I would just use WebRequest.Create and set the ContentLength property. In the PCL library, the ContentLength property is not available. If I try to add a Header with a key of "Content-Length" the framework complains that I should just use the ContentLength property.
Any ideas on how I can set the ContentLength in a PCL?
如果你不能设置ContentLength
属性,但它必须设置为0,你可以尝试调用GetRequestStream
(或BeginGetRequestStram
后面跟着EndGetRequestStream
)而不向Stream
本身写任何东西,这应该将ContentLength
属性更新为其实际值(0,因为没有写任何东西)。
上一篇: 可移植类库中的ViewModel支持