0

将数据作为 json 从 Android 移动设备发送到应用程序服务器时出现跟随错误。但如果我们从 PC 浏览器发送数据,应用程序可以正常工作。从android浏览器发送数据时我们必须做的事情吗?

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]
4

1 回答 1

0

要删除无效字符,请使用 URLEncoder 或 Uri Parsing,如下所示。

从以下信息开始

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");

或者您可以使用 Uri Parsing

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 结尾。

于 2016-03-02T08:59:27.560 回答