Trying to overcome Java UnknownHostException when accessing Postman Mock Server

Hi all,

I’m developing some integration software using a RESTful API in Java 8.

I’m awaiting some test equipment but, without it, I wanted to get started on mocking some of the simpler API calls using a Postman Mock Server.

I’ve had no issues getting the Mock Server and an example API call set up, and those are working fine either from Postman itself or from my web browser - giving the expected mocked response. However, my Java project is giving an UnknownHostException when it tries to connect to that Mock Server. I’ve double-checked the spelling of the Mock Server URI and it is definitely correct.

I’m guessing the exception is because my Java needs a proxy setting up via which it can reach the Mock Server in its Postman format.

Is that correct ?

If so, can someone just give me a few pointers as to the settings that need to go into the Postman Proxy config to achieve this ? Sorry, but I find the Postman Proxy help docs a little confusing!


Hi the UnknownHostException usually happens when java couldn’t resolve the hostname. So if the mockserver is giving you correct response from browser and postman , then you should set proxy settings within the application itself.

I am not sure if there needs to be something done from postman side as postman mockserver is available in cloud and can be accessed

Hi there, and thanks for your original reply.

I’ve made some considerable progress on this, although it wasn’t in the area of proxies as it turned out. I could still do with a clear explanation as to why the following two results differ:

Solution 1)

Whilst I was trying to work out why I wasn’t getting access to my Mock Server, I found some sample code on Stack Overflow for a local HTTPS server which I decided to implement. It worked. I discovered two things:

(a) I was missing a leading “/” in the API part of my GET path - so the context that was configured in my HTTPS server wasn’t being recognised. Silly mistake!

(b) I needed to do some certificate management to mark my new localhost HTTPS server as a trusted host.

Once these two things were done, my own HTTPS server solution worked OK, and I got a valid response to my GET request.

So …

Solution 2)

I then went back to Postman, using EXACTLY the same Java client code as above. I used to certificate management to mark the Postman Mock Server as a valid host, and I knew that the API context was now correct. In the client call, I simply changed the hostname:port target address and sent the request…

I’m now getting a valid response to my GET request. HOWEVER, this occurs ONLY AFTER I receive the following exception:

TLS handshake failed. Cause is: Connection has been shutdown: PKIX path building failed: No issuer certificate for certificate in certification path found.

So whilst I now have a working solution with Postman, I don’t understand why I’m getting the above error even though I’m getting a valid HTTP response - an error that I don’t get with my own local server.

Any thoughts ?

In postman if you goto settings there is an option to turn of ssl validation , it is off by default . In java it is turned on you should add the certificate to java certificate store to remove the certification error I believe