C# 尝试上载到web服务时编码不起作用

C# 尝试上载到web服务时编码不起作用,c#,webserver,C#,Webserver,您好,我正试图通过WebClient向web服务发送数据,但它似乎没有正确地通过密码字段。以下是我的WebClient的代码: using (var client = new WebClient()) { client.Encoding = System.Text.Encoding.UTF8; var response = client.UploadString(string.Format(SendToServiceURL

您好,我正试图通过WebClient向web服务发送数据,但它似乎没有正确地通过密码字段。以下是我的WebClient的代码:

 using (var client = new WebClient())
        {

            client.Encoding = System.Text.Encoding.UTF8;

              var response = client.UploadString(string.Format(SendToServiceURL + "api/SendRequest?Id={0}&product={1}&password={2}", Id, Product, Password),
                        "POST");

            return response;
}

发送前的密码是-
GVg4Vs2您需要使用
HttpUtility.UrlEncode
而不是
HttpUtility.HtmlEncode


HtmlEncode
turns
您需要使用
HttpUtility.UrlEncode
而不是
HttpUtility.HtmlEncode
。但最好不要在查询字符串中输入密码,而是将其作为post数据的一部分。我现在将尝试
HttpUtility.UrlEncode
,是的,我知道这只是我目前的一个测试项目,因为我对WebClient不太熟悉。谢谢这很好谢谢
var encodedPassword = HttpUtility.HtmlEncode(password);