问题
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