Tag: urlencode

如何在URLEncoded或ASP.NET中具有百分比字符时获取查询字符串

当查询字符串是UrlEncoded或在ASP.NET中具有百分比字符时,如何从Request对象获取实际的查询字符串? 基本上,如果我有这样的Url: Default.aspx?p=%b4 ,如何获得填充“%b4”的字符串? Request.QueryString[“p”]返回不可打印的字符。 Request.RawUrl返回Default.aspx?p =%ufffd“ Request.Url.AbsoluteUri返回Default.aspx?p =%EF%BF%BD 我怎样才能得到“%b4”?

System.Uri和编码冒号(:)

在.Net 4.5之前,似乎System.Uri会对编码的斜杠进行编码,但此后已经修复。 参考: https : //stackoverflow.com/a/20733619/188740 我遇到了与冒号相同的问题。 System.Uri仍然编码冒号。 例: var uri = new Uri(“http://www.example.com/?foo=http%3A%2F%2Fwww.example.com”); var s = uri.ToString(); //http://www.example.com/?foo=http:%2F%2Fwww.example.com 注意%3A如何切换回:由System.Uri。 这是一个错误吗? 什么是最好的解决方法?

如何使用HttpWebRequest在POST中转义URL编码数据

我正在尝试将URL编码的post发送到用PHP实现的REST API。 POST数据包含两个用户提供的字符串: WebRequest request = HttpWebRequest.Create(new Uri(serverUri, “rest”)); request.Method = “POST”; request.ContentType = “application/x-www-form-urlencoded; charset=UTF-8”; request.Headers.Add(“Content-Transfer-Encoding”, “binary”); // Form the url-encoded credentials we’ll use to log in StringBuilder builder = new StringBuilder(); builder.Append(“user=”); builder.Append(user); builder.Append(“&password=”); builder.Append(password); byte[] credentials = Encoding.UTF8.GetBytes(builder.ToString()); // Write the url-encoded post data into the request stream. request.ContentLength = credentials.Length; using […]

带有POST编码问题的C#web请求

在MSDN网站上有一些C#代码的示例,它显示了如何使用POST数据发出Web请求。 以下是该代码的摘录: WebRequest request = WebRequest.Create (“http://www.contoso.com/PostAccepter.aspx “); request.Method = “POST”; string postData = “This is a test that posts this string to a Web server.”; byte[] byteArray = Encoding.UTF8.GetBytes (postData); // (*) request.ContentType = “application/x-www-form-urlencoded”; request.ContentLength = byteArray.Length; Stream dataStream = request.GetRequestStream (); dataStream.Write (byteArray, 0, byteArray.Length); dataStream.Close (); WebResponse response = request.GetResponse (); […]

如何URL编码周期?

我需要URL编码一些句点,因为我必须传递一些文档路径,就像这样 http://example.com/test.aspx?document=test.docx 因此test.docx导致我出现非法字符错误。 所以我需要把它改成 . –> %2E 我试着使用Server.UrlEncode string b = Server.UrlEncode(“http://example.com/test.aspx?document=test.docx”); 但我明白了 “http%3a%2f%2fexample.com%2ftest.aspx%3fdocument%3dtest.docx” 那么我是否必须像字符串替换一样使用并手动执行并用该代码替换所有句点?

根据RFC4648,C#:base64url

我正在根据C#中的RFC4648寻找base64url的(快速)标准实现。 我找到了HttpServerUtility.UrlTokenEncode但看起来这并不遵循RFC4648(UrlTokenEncode在末尾添加一个数字,表示已删除的=符号的数量;请参阅此处和此处 )。 例: base64编码: Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes( “AA”)); //返回“QUE =” base64url编码: HttpServerUtility.UrlTokenEncode(System.Text.Encoding.ASCII.GetBytes( “AA”)); //返回“QUE1”,但我希望“QUE”