获得目标主机不能为空或参数为Android HTTP GET方法设置 [英] Getting Target host must not be null or set in parameters in http get method for android

查看:262
本文介绍了获得目标主机不能为空或参数为Android HTTP GET方法设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮我找出我的问题的答案我试图找到在谷歌这么多次,但我不能能够找到它的解决方案。

Please help me to figure out my question answer i tried to find so many times on Google but i cant able to find its solution.

首先我得到这个例外

 java.lang.IllegalArgumentException: Illegal character in query at index 130

不是之后我在code添加此code。

than after i add this code in my code.

String restUrl = URLEncoder.encode(url, "UTF-8");
HttpGet httpget = new HttpGet(restUrl);

然后我得到这个例外

then i am getting this exception

java.lang.IllegalStateException: Target host must not be null, or set in parameters.

请帮我从此异常解决掉。请。

Please help me solve out from this exception. Please.

下面是我的code。

推荐答案

<一个href=\"http://stackoverflow.com/questions/2593214/android-howto-parse-url-string-with-spaces-to-uri-object\">Android: HOWTO解析URL字符串用空格URI对象?

您其实应该URLEn code中的无效的字符。由于该字符串实际上包含了完整的URL,这是很难正确URL-CN code吧。您不知道哪个斜线/应考虑到,哪些不。你不能predict上原始字符串事前。这个问题确实需要在更高层次上得到解决。在这情况下字符串是从哪里来的?它是硬codeD?然后,只需自己相应的更改。它进来作为用户输入?验证它,并显示错误,让用户自行解决。

You should in fact URLEncode the "invalid" characters. Since the string actually contains the complete URL, it's hard to properly URL-encode it. You don't know which slashes / should be taken into account and which not. You cannot predict that on a raw String beforehand. The problem really needs to be solved at a higher level. Where does that String come from? Is it hardcoded? Then just change it yourself accordingly. Does it come in as user input? Validate it and show error, let the user solve itself.

这篇关于获得目标主机不能为空或参数为Android HTTP GET方法设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆