C# Uri.EscapeDatastring() equivalent for Java

a 夏天 提交于 2019-12-10 13:43:01

问题


We've implemented an HTTP authentication connection, encoded in C# with Uri.EscapeDataString().

I'm trying to make an identical java test application that does the exact same thing as the C# version, but URLEncoder.encode(string, "UTF-8") adds additional encoding that isn't quite the same as the C# Uri.EscapeDataString() function.

What's the equivalent encoding method?


回答1:


The best way I've found to do this is to use the URL.toURI().toString() combo:

String uriEncodeVariable = "https://localhost:443";
URL tempURL = new URL(uriEncodeVariable);
String uriResult = tempURL.toURI().toString();



回答2:


I'm not very fluent in C# but it looks like you need something like URLEncoder ? Let's have a look to SO 213506 (http://stackoverflow.com/questions/213506/java-net-urlencoder-encodestring-is-deprecated-what-should-i-use-instead) ?



来源:https://stackoverflow.com/questions/8317505/c-sharp-uri-escapedatastring-equivalent-for-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!