我收到一個錯誤,並且收到了關於如何編碼我的請求的API手冊。以下是我的要求..XML響應錯誤:在文檔的頂級無效
string url = "[My url to send request to]";
string xmlrequest = "<serv_request><head><securityContext><account>[account]</account><key>[my account key]</key></securityContext></head><body><username>[my user name]</username></body></serv_request>";
NameValueCollection nvc = new NameValueCollection();
nvc.Add("xml", Server.UrlEncode(xmlrequest));
WebClient client = new WebClient();
byte[] byteresponse = client.UploadValues(url, nvc);
string xmlresponse = client.Encoding.GetString(byteresponse);
我得到一個迴應的錯誤。在文檔的頂層無效。
編輯..添加從提供給我的API說明手冊..
string url = " http://[domain_name]/_gateway/api/[filename].asp";
// formulate the XML request here
string xmlrequest = "<serv_request>...</serv_request>";
NameValueCollection nvc = new NameValueCollection();
nvc.Add("xml", Server.UrlEncode(xmlrequest));
WebClient client = new WebClient();
byte[] byteresponse = client.UploadValues(url, nvc);
string xmlresponse = client.Encoding.GetString(byteresponse);
用xml標籤開始字符串? '<?xml version =「1.0」encoding =「UTF-8」?>' – marekful
感謝您的回覆,當您試圖將其作爲... string xmlrequest =「<?xml version ='1.0'encoding ='UTF-8 '?>培訓 [我的鑰匙代碼] SecurityContext的> [我的用戶名] serv_request>」我收到了同樣的錯誤。 –
您是否曾嘗試在開始的標籤中包含XML名稱空間屬性?就像'' –
X3074861X