我是android的新手,我有这个网址,现在我需要编码这个网址:the url that has to be encoded。 使用Java在Mobile中下载apk的参考如何将此URL传递给此行:
updateAppInstance.execute("http://demo.ingresssolutions.com/proposalmanagement/services/user/getApkFile");
Previous post Regarding Apk Download
http://demo.ingresssolutions.com/proposalmanagement/services/user/uploadFile
答案 0 :(得分:0)
与您将阅读的许多答案相反,java.net.URLEncoder不用于编码URL。它用于编码URL和POST 参数。
在Java中编码URL的正确方法如this answer中所述,或者,如果您只需要对路径组件进行编码:
String encodedPath = new URI(null, path, null).toASCIIString();
答案 1 :(得分:-1)
import java.net.URL;
import java.net.URLEncoder;
import java.net.MalformedURLException;
import java.io.UnsupportedEncodingException;
public class Encoder{
public static void main(String[] args){
URL url = null;
try{
url = new URL("http://www.stackoverflow.com");
}catch(MalformedURLException mue){
System.err.println(mue);
}
System.out.println(url + "
");
try{
String encodedurl = URLEncoder.encode(url.toString(),"UTF-8");
System.out.println(encodedurl);
}catch(UnsupportedEncodingException uee){
System.err.println(uee);
}
}
}
希望这有助于你