开发者

Android/java: String url does not work in HttpGet(url)

I construct a string with a value I get from another activity:

Bundle b = getIntent().getExtras();

value = b.getString("bundledata");

url = "http://dl.dropbox.com/u/xxx/apptextfiles/";
url += value;
url +=开发者_运维问答 ".txt";

so, the string url looks like http://dl.dropbox.com/u/xxx/apptextfiles/LFC2.txt

Later on I try to read the textfile with HttpGet request = new HttpGet(url) - and the app crash. The strange thing is that if I write url = "http://dl.dropbox.com/u/xxx/apptextfiles/LFC2.txt" it works fine, but not if I construct it like above. Actually, if I take the url value from eclipse and put it in a browser it changes to http://dl.dropbox.com/u/xxx/apptextfiles/%EF%BB%BFLFC2.txt - why?? It look like som strange encoding issue? The string value I get from the other activity is also taken from an online textfile. Anyone has a clue about how to solve this?


Take a look at http://www.w3schools.com/tags/ref_urlencode.asp

It looks like the value field you have in your url string contains special characters -- ï , » and ¿

Thats the reason for your url getting encoded as you referenced. Use a hexeditor or something to make sure your textfile does not contain special characters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜