我必须将URL更改为URI,请指导我如何更改。
我尝试了很多,但都没有得到解决方案。感谢您的帮助。如果需要,我还可以附上代码片段。
我们可以使用Uri.parse(String)方法解析任何URL。
代码段:
Uri uri = Uri.parse( "http://www.stackoverflow.com" );
final String myUrlStr = "xyz";
URL url;
Uri uri;
try {
url = new URL(myUrlStr);
uri = Uri.parse( url.toURI().toString() );
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
这是我的2美分,它可以帮助其他人。
如果将变量作为查询传递到URL,那么标准的URL解析可能不是一个好主意
String your_url_which_is_not_going_to_change = "http://stackoverflow.com/?q="
String your_query_string = "some other stuff"
String query = null;
try {
query = URLEncoder.encode(your_query_string, "utf-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String url = your_url_which_is_not_going_to_change + query;
URL input = new URL(url);
etc... .
希望能有所帮助。
H。
var url="http://10.0.2.2:8080/(mymobileapp)/login.php";;
var response=等待http.post(Uri.parse(url),body:data);