2
我希望能夠讓我的Web服務接受多個POST參數,其中一些參數是XML。這可能嗎?以下代碼將生成服務器錯誤:多個POST參數,其中一些包含XML
WebResponse resp =(WebResponse)req.GetResponse();
string programId = "1";
string statusMessages = statusMessagesXML.ToString(SaveOptions.DisableFormatting);
string postData = "programId=" + programId;
postData += "&statusMessages=" + HttpUtility.UrlEncode(statusMessages);
string data = postData;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = data.Length;
req.Method = "POST";
StreamWriter writer = new StreamWriter(req.GetRequestStream());
writer.Write(data);
writer.Flush();
writer.Close();
String result = null;
WebResponse resp = (WebResponse)req.GetResponse();
Stream readstream = resp.GetResponseStream();
StreamReader read = new StreamReader(readstream);
result = read.ReadToEnd();
感謝。
什麼是服務器錯誤?你也提到想要調用一個「Web服務」,但是這看起來並不像你正在與WebService交互。也許你只是用通用的HTTP意思來表示它? – kaliatech 2010-10-20 21:49:53
當您將狀態消息作爲簡單字符串而不是XML傳遞時,它會起作用嗎? – kaliatech 2010-10-20 21:50:47
是的。看起來 abc」就沒關係。此外,它是一個RESTful服務,而不是.NET SOAP Web服務。 –
2010-10-21 05:08:20