gpt4 book ai didi

c# - 多个 POST 参数,一些包含 XML

转载 作者:行者123 更新时间:2023-11-30 18:47:12 25 4
gpt4 key购买 nike

我希望能够让我的网络服务接受多个 POST 参数,其中一些是 XML。这可能吗?下面的代码将产生一个服务器错误:

WebResponse resp = (WebResponse)req.GetResponse();


string programId = "1";
string statusMessages = statusMessagesXML.ToString(SaveOptions.DisableFormatting);<p></p>

<pre><code> 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();
</code></pre>

<p></p>
谢谢。

最佳答案

问题是:

req.ContentType = "application/x-www-form-urlencoded";

这告诉服务器您的数据是 URL 编码的,并且“<”是 URL 元字符。要么对您的数据进行 URLEncode,要么不告诉服务器数据已进行 URLEncoded,但实际上并未。

关于c# - 多个 POST 参数,一些包含 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3982569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com