2012-10-08 76 views
0

從Android移動設備將數據作爲json發送到應用程序服務器時,我收到了跟蹤錯誤。但是,如果我們從PC瀏覽器發送數據,應用程序沒有任何問題。從android瀏覽器發送數據時,我們需要做些什麼?URI解析錯誤

Caused by: java.net.URISyntaxException: Illegal character in query at index 271: http://oracleapps.veeralab.com:8080/emyed-whiteboard/pubsub/27c95d04-9783-447b-b333-bcc7b3bbb6b7/01815406-7699-4c2c-ae4b-4eefdbbcbdf0.topic?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=1.0&X-Atmosphere-Transport=polling&X-Cache-Date=0&X-Atmosphere-Post-Body=message={%22action%22:%22joinName%22,%22parameters%22:%22usersName%22:%22veera,%20job,%20ram%22,%22timestamp%22:1349724088883,%22user%22:%22job%22,%22whiteboardId%22:%2227c95d04-9783-447b-b333-bcc7b3bbb6b7%22}&jsonpTransport=jQuery180031574026358131124_1349709680844 
     at java.net.URI$Parser.fail(URI.java:2829) [rt.jar:1.7.0_05] 
     at java.net.URI$Parser.checkChars(URI.java:3002) [rt.jar:1.7.0_05] 
     at java.net.URI$Parser.parseHierarchical(URI.java:3092) [rt.jar:1.7.0_05] 
     at java.net.URI$Parser.parse(URI.java:3034) [rt.jar:1.7.0_05] 
     at java.net.URI.<init>(URI.java:595) [rt.jar:1.7.0_05] 
     at java.net.URI.create(URI.java:857) [rt.jar:1.7.0_05] 
+0

編碼您的URI,擺脫大括號 – 16dots

+0

@ 16dots但我不明白爲什麼它在計算機瀏覽器中工作,它應該也會失敗 – user1595858

+0

因爲您的瀏覽器自動爲您編碼的一切。 – 16dots

回答

0

要刪除無效字符,請按如下所示使用URLEncoder或Uri分析。

以下信息

String BASE_URL = "http://oracleapps.veeralab.com:8080/emyed-whiteboard/pubsub/27c95d04-9783-447b-b333-bcc7b3bbb6b7/01815406-7699-4c2c-ae4b-4eefdbbcbdf0.topic" 
String QUERY = "X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=1.0&X-Atmosphere-Transport=polling&X-Cache-Date=0&X-Atmosphere-Post-Body=message={%22action%22:%22joinName%22,%22parameters%22:%22usersName%22:%22veera,%20job,%20ram%22,%22timestamp%22:1349724088883,%22user%22:%22job%22,%22whiteboardId%22:%2227c95d04-9783-447b-b333-bcc7b3bbb6b7%22}&jsonpTransport=jQuery180031574026358131124_1349709680844" 

您可以使用URLEncoder的

String url = BASE_URL + "?" + URLEncoder.encode(QUERY, "utf-8"); 

或者您可以使用開放的解析

String uri = Uri.parse(BASE_URL) 
      .buildUpon() 
      .appendQueryParameter("X-Atmosphere-tracking-id", "0") 
      .appendQueryParameter("X-Atmosphere-Framework", "1") 
      .appendQueryParameter("X-Atmosphere-Post-Body", "message={%22action%22:%22joinName%22,%22parameters%22:%22usersName%22:%22veera,%20job,%20ram%22,%22timestamp%22:1349724088883,%22user%22:%22job%22,%22whiteboardId%22:%2227c95d04-9783-447b-b333-bcc7b3bbb6b7%22}") 
      ... //your other params 
      .build().toString(); 
啓動

我的建議是使用Uri Parsing方法來確保不應該編碼任何東西,但是您仍然以有效的URI結束。