Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 可移植类库&;WebRequest.ContentLength_C#_.net_Httpwebrequest_Webrequest_Portable Class Library - Fatal编程技术网

C# 可移植类库&;WebRequest.ContentLength

C# 可移植类库&;WebRequest.ContentLength,c#,.net,httpwebrequest,webrequest,portable-class-library,C#,.net,Httpwebrequest,Webrequest,Portable Class Library,我有一个可移植类库,目标是.NET for Windows应用商店应用程序和“Windows Phone 7.5或更高版本”。我发出HTTP POST请求,从上周开始,负责后端的管理员决定我需要发送ContentLength 0,而不是.NET默认的-1。我使用WebRequest类,但如果需要,我可以灵活地使用HttpWebRequest 通常我只使用WebRequest。创建并设置ContentLength属性。在PCL库中,ContentLength属性不可用。如果我试图添加一个带有键“C

我有一个可移植类库,目标是.NET for Windows应用商店应用程序和“Windows Phone 7.5或更高版本”。我发出HTTP POST请求,从上周开始,负责后端的管理员决定我需要发送ContentLength 0,而不是.NET默认的-1。我使用WebRequest类,但如果需要,我可以灵活地使用HttpWebRequest

通常我只使用WebRequest。创建并设置ContentLength属性。在PCL库中,ContentLength属性不可用。如果我试图添加一个带有键“ContentLength”的头,框架会抱怨我应该只使用ContentLength属性


关于如何在PCL中设置ContentLength的任何想法?

如果不能设置
ContentLength
属性,但必须将其设置为0,则可以尝试调用
GetRequestStream
(或
BeginGetRequestStram
后接
EndGetRequestStream
),而不向
流本身写入任何内容,这应该更新<代码> Cordon Stime//Cux>属性到它的实际值(0,因为没有写任何东西)。

如果你在没有中间写任何东西的情况下,你将生成PrimeEngestRestStand()和EngestReestStestRoad()。它应该是一个长度为0的流(并且它可能会强制在头中使用ContentLength)。你能把它作为一个答案吗?这实际上解决了我的问题。我花了一些时间来解决这个问题。谢谢你的回答!解决方案有时非常简单:-)。