如果您運行此代碼,它將引發WebException。內部異常是「無法爲不寫入數據的操作設置Content-Length或Chunked Encoding」。我不明白問題的本質。任何人都可以將光投射到這個黑暗的角落?爲什麼此例外聲明代碼不寫入數據?
using System.Diagnostics;
using System.Net;
using System.Text;
namespace sandpit
{
static class Program
{
static void Main()
{
string INITIAL_URI = "http://docs.live.net/SkyDocsService.svc";
string SOAP = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><GetWebAccountInfoRequest xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://schemas.microsoft.com/clouddocuments\"><BaseRequest><ClientAppId>SkyDrive Service Client</ClientAppId><Market>en-US</Market><SkyDocsServiceVersion>v1.0</SkyDocsServiceVersion></BaseRequest><GetReadWriteLibrariesOnly>false</GetReadWriteLibrariesOnly></GetWebAccountInfoRequest></s:Body></s:Envelope>";
using (WebClient wc = new WebClient())
{
wc.Encoding = Encoding.UTF8;
wc.Headers["SOAPAction"] = "GetWebAccountInfo";
wc.Headers["Accept-Language"] = "en-US";
wc.Headers["Accept"] = "text/xml";
wc.Headers["Content-Type"] = "text/xml; charset=utf-8";
string response = wc.UploadString(INITIAL_URI, SOAP);
Debug.WriteLine(response);
}
}
}
}
在這種情況下, false GetReadWriteLibrariesOnly>是什麼意思? –
ChrisF
GetReadWriteLibraries是本質上是查詢的過濾器值。這不相關;如果live.com不喜歡我的查詢,我會收到回覆說,所以不是發送barf。漢斯,我會嘗試一下魔法重啓的咒語,看看它是否會讓我的量子位回到更理智的世界。 –
我注意到我只能使用
,因爲我真的只在響應頭之後。 –