发布XML数据时,我不断收到臭名昭着的“Root元素缺失”错误。它有时会起作用,但大多数时候会抛出错误。
C#代码:
public string postXMLData(string destinationUrl, string requestXml)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(destinationUrl);
byte[] bytes;
bytes = System.Text.Encoding.ASCII.GetBytes(requestXml);
request.ContentType = "text/xml; encoding='utf-8'";
request.ContentLength = bytes.Length;
request.Method = "POST";
Stream requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
HttpWebResponse response;
response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream responseStream = response.GetResponseStream();
string responseStr = new StreamReader(responseStream).ReadToEnd();
return responseStr;
}
return "";
}
XML数据:
<Person>
<idPeople>0</idPeople>
<AccountNumber>TEST02H</AccountNumber>
<cFirstName>TEST 2</cFirstName>
<cLastName>TEST 2</cLastName>
<cTelWork/>
<cTelMobile>0713473835</cTelMobile>
<cEmail>myemail@mydomain.com</cEmail>
<ubPPLIsActive>true</ubPPLIsActive>
<ubPPLSMSOptIn>true</ubPPLSMSOptIn>
<udPPLSMSOptInActivateDate>30/05/2017</udPPLSMSOptInActivateDate>
<ulPPLAccessType>Administrator</ulPPLAccessType>
<ubPPLNewsletterSignUp>true</ubPPLNewsletterSignUp>
<ubPPLIncludeBuyerEmails>true</ubPPLIncludeBuyerEmails>
</Person>
答案 0 :(得分:0)
对我来说问题是在两个地方。
我发布的应用程序出错了,我已经解决了。我通过将目标网址粘贴到浏览器中发现了这个错误,看看会发生什么。
我需要System.Web.HttpUtility.UrlEncode XML。
我最后用这种方法发帖。
select status, start_time, end_time, datediff(s,start_time,end_time) duration
from catalog.executions
where project_name = 'exec-ssis-stored-proc-ssis-sample'
and package_name = 'Sample.dtsx'
order by execution_id