lookingonthew3schoolsurlencodingwebpage,it says that @ should be encoded as @,和that space should be encoded as。
I've tried both陶醉的舞蹈and URI,butneitherdoestheaboveproperly 3360
import java.net.URI;
import java.net .陶醉的舞蹈;
公共类测试{
publicstaticvoidmain (字符串紧凑的秋季args ) throws Exception { )。
//printsme@home.com(correct ) )。
//prints电子邮件地址(wrong : should be电子邮件地址)。
// http://www.home.com/test? Email Address=me@home.com
//wrong : ithasnotencodedthe @ in the email address )
uriuri=newuri('http ',' www.home.com ','/test ',' Email Address=me@home.com ',null );
}
}
For some reason,陶醉的舞蹈doestheemailaddresscorrectlybutnotspaces,anduridoesspacescurrencybutnotemailaddresses。
howshouldiencodethese2parameterstobeconsistentwithwhatw3schoolssaysiscorrect (oris w3schools wrong? )
althoughithinktheanswerfrom @ fgeistherightone,asiwasusinga3rdpartywebservicethatreliedontheencodingoutlinedinthew 3方案阵列ifollowedtheanswerfromjavaequivalenttojavascript ' sencodeuricomponentthatproducesidenticaloutput?
publicstaticstringencodeuricomponent {
字符串结果;
try {
result=陶醉的舞蹈. encode(s,' UTF-8 ' ) ) ) )。
.替换所有(()、() ) )
. replaceall('!' ,'!' )
. replaceall('',wndpy ) )。
. replaceall(')、') ) )
.替换所有(()、()、() ) ) )
. replaceall (((((、) ) ) ) ) );
} catch (unsupportedencodingexceptione ) {
结果=s;
}
返回结果;
}