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

前端 未结 3 2067
旧时难觅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 06:49

    Since your content-type is application/x-www-form-urlencoded you'll need to encode the POST body, especially if it contains characters like & which have special meaning in a form.

    Try passing your string through HttpUtility.UrlEncode before writing it to the request stream.

    Here are a couple links for reference.

    • http://en.wikipedia.org/wiki/Percent-encoding

提交回复
热议问题