C# HttpWebRequest of type “application/x-www-form-urlencoded” - how to send '&' character in content body?

前端 未结 3 2064
旧时难觅i
旧时难觅i 2020-11-29 06:28

I\'m writing a small API-connected application in C#.

I connect to a API which has a method that takes a long string, the contents of a calendar(ics) file.

I

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 07:08

    As long as the server allows the ampresand character to be POSTed (not all do as it can be unsafe), all you should have to do is URL Encode the character. In the case of an ampresand, you should replace the character with %26.

    .NET provides a nice way of encoding the entire string for you though:

    string strNew = "&uploadfile=true&file=" + HttpUtility.UrlEncode(iCalStr);
    

提交回复
热议问题