Target host must not be null, or set in parameters

徘徊边缘 提交于 2019-11-26 23:34:44

问题


I get this error "Target host must not be null, or set in parameters". My manifest file has internet permission set, and I have put 'http://' before my Url. It still gives the same error. My URL does not have a 'www.' attached to it.

Part of my Code:

HttpPost post = new HttpPost("http://infocreation.something_something1.xml");

Part of my manifest is like below:

<uses-permission android:name="android.permission.INTERNET/>

What do I do now?


回答1:


It should be

HttpPost post = new HttpPost("http://www.infocreation.something.xml");



回答2:


So I replaced the URL, with almost the same URL, except without the underscore and that worked. I realized from further searches (for example here) that URLs with _(underscore) are not valid, although that particular URL may work. Thanks for all your help.




回答3:


Are you putting a real and working url inot the HttpPost constructor?

Anyway this is your solution:

If you have the following code failing:

HttpGet httpget = new HttpGet("www.host.com");

Then the error is pretty easy to solve: The problem is that you have not added a protocol to the URL, so change it to:

HttpGet httpget = new HttpGet("http://www.host.com");

And then it will work as wanted.

Source: h3x.no



来源:https://stackoverflow.com/questions/8759108/target-host-must-not-be-null-or-set-in-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!