1

I have googled but many concerns was "java.lang.IllegalStateException: Target host must not be null", but in my case error was "java.lang.IllegalStateException: Target host is null"

I am trying to post a request using following code

StringEntity reqContent = new StringEntity(xmlData);
reqContent.setContentType("text/xml");

HttpPost req = new HttpPost(serverURL);
req.setEntity(reqContent);

httpClient = new DefaultHttpClient(connMgr, params);

httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(username, password));

HttpResponse response = httpClient.execute(req);

After executing the request I am getting "Target host is null". I am giving a valid host. Does this error comes when Target host which I am trying to access is not available?

1
  • Are you giving a valid domain or a valid url. This error actually states out that you probabely missing the protocol in the url. This happens if you just send the domain (without the protocolk http:// or https://) Commented Mar 1, 2019 at 15:11

2 Answers 2

6

In my case also "http://" was missing

Sign up to request clarification or add additional context in comments.

Comments

2

When sending a request , somehow my URL which I want to send the request to is getting null which caused this issue when I am trying to execute a request.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.