导读: 仅供使用httpclient库模拟http请求,Post请求头git
"数据被编码成以'&'
分隔的键-值对, 同时以'='
分隔键和值 . 非字母或数字的字符会被 percent-encoding" 援引: https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Methods/POST
HttpUtility.UrlEncode(string str)
使用 urlencode方法,对请求体的body内存在须要转义字符时提早进行转义.好比"+"转义为"%2b"," "转义为"+"或"%20" 援引 https://developer.mozilla.org/zh-CN/docs/Glossary/percent-encodinggithub
而后再拼接为字符串以提供给StringContent所需的content参数.数组
3:接收参数浏览器
本实验使用.NET Framework 4.5 默认生成的MVC框架模拟接受Form请求参数.app
另附curl仅供参考框架
curl --location --request POST 'https://localhost:44343/home/GetUserInfo' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'k=1%2b1'
4:结束语curl
整日搬砖,却对方法体不求甚解.借此记录,以供参考编码