Postman can authentication but connection refused from eclipse java

I can use postman to authentication successful, but when I tried to connect from java on same PC network, I got Failed to connect to, my code as below, what can I do?

OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n    \"tenancyName\": \"postman\",\n    \"usernameOrEmailAddress\": \"admin\",\n    \"password\": \"postman123\"\n}");
Request request = new Request.Builder()
		  .addHeader("Content-Type", "application/json")
		  .addHeader("User-Agent", "PostmanRuntime/7.13.0")
		  .addHeader("Accept", "*/*")
		  .addHeader("Cache-Control", "no-cache")
		  .addHeader("Postman-Token", "c9e50ee5-9136-4ac2-8dda-5234d346c702,21afd573-f446-4677-8ea5-2e09131e0b51")
		  .addHeader("Host", "")
		  .addHeader("cookie", "__cfduid=d99b720ea5889570669d827c9dc7176911556243061; ASP.NET_SessionId=qckzu2aie1fxie5g3nqvlnuh; __RequestVerificationToken=G7jlQDTPpSAFN7iz2SLHH4X89lIbR-QjxtT_ctnzO4p_J__2LmboS4ykraoBfe6XCChqKvy6SL_4FriLoO_HF0VDD6XHXsbswP8gSHY8nxc1")
		  .addHeader("accept-encoding", "gzip, deflate")
		  .addHeader("content-length", "101")
		  .addHeader("Connection", "keep-alive")
		  .addHeader("cache-control", "no-cache")
		  .build(); .

Hi Mike,

Welcome to the forum. Just one though is that you could check that a remote remote connection through port 443 is allowed in the firewall settings of the PC?

Well, I can check it. But why postman is no any problems to connect even if 443 is closed?

Can you give me more detail information to check what on PC?

Might be an application specific rule allowing it through.
Check firewall settings like this on Windows 7/Server 2012:

  1. Open Control Panel and search “firewall” (Or if Windows 10 just search “firewall settings” from the start menu).
  2. Click “Windows Firewall” and open the “Advanced Settings”.
  3. Go to “Outbound Rules” and check there for rules on Remote Port 443…

You could also create a new rule allowing the connection

Also, does that exact same request structure work in postman?

Lastly, have a read of this post and see if any of those links can assist you as well:

I added a new rule to allow port 443 out, but I got the same result Failed to connect to

I found problem because my PC has to connect outside server with proxy, and postman used proxy settings in Chrome.
I met new problem after I set proxy, that is connect timed out, what can I do next?