我正在尝试像这样发送一个简单的 HTTP 请求:
var client = new WebClient();
string myString="this is the string i want to send";
message = client.DownloadString("http://www.viralheat.com/api/sentiment/review.xml?text=" + myString + "&api_key="+currentKey);
但是我发送的一些字符串包含#或&之类的字符,所以我想在发送之前先对字符串进行编码,因为如果它包含这些特殊字符而不进行编码会抛出错误。
最佳答案
调用Uri.EscapeDataString
.
与 HttpUtility
不同,这也适用于客户端配置文件。
关于c# - 编码我的字符串以通过 C# 发送 http 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7968875/