相关疑难解决方法(0)

C#HttpWebRequest类型为"application/x-www-form-urlencoded" - 如何在内容体中发送'&'字符?

我正在用C#编写一个API连接的小应用程序.

我连接到一个API,它有一个采用长字符串的方法,即日历(ics)文件的内容.

我是这样做的:

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();
 }
Run Code Online (Sandbox Code Playgroud)

这似乎很有效,直到我在我的日历中添加一些特定的HTML.

如果我在我的日历(或类似)中的某个地方有一个' ',那么服务器只会获得所有数据到'&' - 点,所以我假设'&'使得它看起来像这个点之后的任何东西属于一个新参数?

我怎样才能解决这个问题?

c# post httpwebrequest

32
推荐指数
3
解决办法
8万
查看次数

标签 统计

c# ×1

httpwebrequest ×1

post ×1