12

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?

King of Masses
  • 18,405
  • 4
  • 60
  • 77
Ama
  • 195
  • 1
  • 1
  • 9
  • 1
    Just to be clear: there is no such thing as an ".xml" TLD, so either your example-URI above is badly chosen, or you are trying to do something strange. If your real code also has the `.xml`, then there's your problem: there is no such thing to send a HTTP request to. – Nanne Jan 07 '12 at 10:15
  • Thank you for your response. Using the URL without the underscore has worked for me. The .xml part is ok. – Ama Jan 07 '12 at 10:22
  • by the way, I was getting this error because I forgot to add http://. I was writing www.something.com, but it must be http://www.something.com – PeerNet May 24 '16 at 09:39

3 Answers3

10

It should be

HttpPost post = new HttpPost("http://www.infocreation.something.xml");
coder_For_Life22
  • 26,645
  • 20
  • 86
  • 118
7

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.

Community
  • 1
  • 1
Ama
  • 195
  • 1
  • 1
  • 9
7

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

StErMi
  • 5,389
  • 5
  • 48
  • 71
  • Thank you Nanne. I didn't put the real URL in the question. The real URL doesn't have a www. attached to it. And I am using POST, not GET. Thank you. – Ama Jan 07 '12 at 10:21
  • You error was not refered to HttpGet or HttpPost, it was general. The error was because you were not putting the http://www or your url was wrong formed. – StErMi Jan 07 '12 at 10:31