gpt4 book ai didi

java - 当我从 android ADB 调用我的网络服务时,10.0.2.2 中存在非法字符

转载 作者:行者123 更新时间:2023-12-01 15:22:39 24 4
gpt4 key购买 nike

我使用 netbeans (Java EE) 制作了一个 Web 服务,并且我想与我的 Android 应用程序(使用 Eclipse 制作)进行通信。

例如,当我尝试通信时,我通过浏览器调用我的网络服务:

localhost:9999/SupRails_Start/resources/rest/mail@gmail.com/password

...它给了我一个 JSON,...

对于 ADB,我将其称为 URI:

10.0.2.2:9999/SupRails_Start/resources/rest/mail@gmail.com/password

但它给了我

java.lang.IllegalArgumentException: Illegal character in scheme at index 0: 10.0.2.2:0000/SupRails_Start/resources/rest/...

当我将 JSON(从浏览器接收到)复制粘贴到 php 页面并将其托管在网络上时,它运行得很好!

这是我的 Android 项目的一部分:

WebService webService = new WebService("10.0.2.2:9999/SupRails_Start/resources/rest/wil.nad@gmail.com/root");
Map<String, String> params = new HashMap<String, String>();
String temp = webService.webGet("", params);
Log.v("", "JSON received = "+temp);

请帮助我,我不明白我的错误...非常感谢!

最佳答案

您的网络服务 URL 不完整。有效 URL 的语法如下:

scheme://domain:port/path?query_string#fragment_id

Every URL consists of some of the following: the scheme name (commonly called protocol), followed by a colon, two slashes,[note 1] then, depending on scheme, a server name (exp. ftp., www., smtp., etc) followed by a dot (.) then a domain name[note 2] (alternatively, IP address), a port number, the path of the resource to be fetched or the program to be run, then, for programs such as Common Gateway Interface (CGI) scripts, a query string,[7][8] and an optional fragment identifier.

[Wikipedia]

所以改变这个:

new WebService("10.0.2.2:9999/SupRails_Start/resources/rest/wil.nad@gmail.com/root")

对此:

new WebService("http://10.0.2.2:9999/SupRails_Start/resources/rest/wil.nad@gmail.com/root")

关于java - 当我从 android ADB 调用我的网络服务时,10.0.2.2 中存在非法字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10674295/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com