【发布时间】:2014-11-02 17:22:05
【问题描述】:
我的代码中出现错误“Illegal character in URL”,但我不知道为什么:
我有一个字符串类型的令牌和哈希。
String currentURL = "http://platform.shopyourway.com" +
"/products/get-by-tag?tagId=220431" +
"&token=" + token +
"&hash=" + hash;
HttpURLConnection urlConnection = null;
BufferedReader reader = null;
try {
URL url = new URL(currentURL);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.connect();
[...]
但是当我写的时候:
URL url = new URL("http://platform.shopyourway.com/products/get-by-tag?tagId=220431&token=0_11800_253402300799_1_a9c1d19702ed3a5e873fd3b3bcae6f8e3f8b845c9686418768291042ad5709f1&hash=e68e41e4ea4ed16f4dbfb32668ed02b080bf1f2cbee64c2692ef510e7f7dc26b");
这是工作,但我不能写这个订单,因为我不知道哈希和令牌,因为我每次都生成它们。 谢谢。
【问题讨论】:
-
在你的价值观上使用URLEncoder
-
变量
token和hash中有什么? -
所以,打印哈希值和token值,找出哪个字符是非法的。如果你真的需要那个非法字符,对它们进行 ure 编码:docs.oracle.com/javase/7/docs/api/java/net/URLEncoder.html
-
示例:字符串令牌="0_11825_1415294906_2_b81903a2c188992baf532183c49621df010f94f10859b261ee1fa0d2bcfcabcf"
-
异常不告诉你在哪里吗?