编码我的字符串以通过C#发送http请求

时间:2011-11-01 15:35:14

标签: c# .net http url-encoding

我正在尝试发送一个简单的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);

但我发送的一些字符串包括#或&或者这样的字符,所以我想在发送之前先对字符串进行编码,因为如果它包含这些特殊字符而不进行编码就会引发错误。

2 个答案:

答案 0 :(得分:6)

致电Uri.EscapeDataStringHttpUtility不同,这也适用于客户端配置文件。

答案 1 :(得分:5)