I'd Like to be able to have my web service accept multiple POST parameters, some of which will be XML. Is this possible? The code below will generate a server error:
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.GetRe开发者_JAVA百科questStream());
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();
Thanks.The problem is:
req.ContentType = "application/x-www-form-urlencoded";
This tells the server your data is URL-encoded, and '<' is a URL metacharacter. Either URLEncode your data, or don't tell the server the data is URLEncoded when it isn't.
精彩评论