首页 > 编程知识 正文

java urlencode,javauriutil

时间:2023-05-06 16:51:37 阅读:40115 作者:4313

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;

}

返回结果;

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。