我正在自动执行登录过程,在此过程中,我将获得包含特殊字符的不同类型的密码。
我的代码如下,我尝试 UrlEncode() 密码,但没有用。如果您在我的代码中发现任何问题,或者我可以找到解决方法,请告诉我。我的密码是 "aab$#*#%232" 和 "@#:.;$%^&+-_h1&" :
string uriString = "http://" + IP + URI ;
string postData = "";
TraceLine("The uri string is " + uriString);
foreach (string key in values.AllKeys)
{
TraceLine(key + " " + values[key]);
postData += key + "=" + values[key] + "&";}}
if (postData.Length > 0) {
postData = postData.TrimEnd(postData[postData.Length - 1]);
}
TraceLine("The postData string is " + postData);
HttpWebRequest req =(HttpWebRequest)System.Net.WebRequest.Create(uriString);
req.ContentType = "application/x-www-form-urlencoded";
req.KeepAlive = false;
req.Method = "POST";
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(postData);
req.ContentLength=bytes.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();}
Run Code Online (Sandbox Code Playgroud)
你实际上得到了正确的结果。看,字符串被转义以使其兼容通过 HTTP 发送。你想要:“aab$## %232”但你得到:“aab%24%23 %23%25232”
%24 = $
%23 = #
%25 = %
为了获得您想要的字符串,您只需使用Uri.UnescapeDataString方法取消转义字符串。
string str = Uri.UnescapeDataString("aab%24%23*%23%25232");
Run Code Online (Sandbox Code Playgroud)
我仍然想劝阻您不要以纯文本形式发送和接收敏感数据,即使它已被转义。也许来自加密的东西会有所帮助?
| 归档时间: |
|
| 查看次数: |
8773 次 |
| 最近记录: |