我正在使用C#编写一个小型API连接的应用程序。
我连接到一个具有接受长字符串(即ics文件的内容)的方法的API。
我这样做:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL);
request.Method = "POST";
request.AllowAutoRedirect = false;
request.CookieContainer = my_cookie_container;
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request.ContentType = "application/x-www-form-urlencoded";
string iCalStr = GetCalendarAsString();
string strNew = "&uploadfile=true&file=" + iCalStr;
using (StreamWriter stOut = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII))
{
stOut.Write(strNew);
stOut.Close();
}
这看起来很好,但当我在我的日历中添加一些特定的HTML时就出现了问题。
如果我的日历中有一个" "(或类似的),那么服务器只会获取到"&"之前的所有数据,所以我认为"&"会让它看起来像是任何在此点之后的内容都属于一个新参数?
我该如何解决这个问题?