如果您运行此代码,它将引发 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);
}
}
}
}