Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Connection refused and Connection timed out exception while sending a post request to the rest api


I am trying to send a post request for login to my Rest API which should have a username and password in the body. I am trying to run the same request on POSTMAN and it works pretty fine whereas when I run the script on SccriptRunner with the same credentials and the URL it Says (Connection refused) and the whole log is as below Connection refused (Connection refused)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(
at org.apache.http.impl.client.DefaultRequestDirector.execute(
at org.apache.http.impl.client.AbstractHttpClient.doExecute(
at org.apache.http.impl.client.CloseableHttpClient.execute(
at org.apache.http.impl.client.CloseableHttpClient.execute(
at org.apache.http.impl.client.CloseableHttpClient.execute(
at$ Source)


Here is my Script

if I try the IP address in the script, it says Connection timed out and if I use link address, it says connection refused. What U might be doing wrong?

import static*
import static*
import groovy.json.JsonSlurper
import net.sf.json.groovy.JsonSlurper

def http = new HTTPBuilder('http://address-to-api:port/login')
http.request(POST) {
requestContentType = ContentType.JSON
body = [username: 'username', password: 'password']

response.success = { resp, JSON ->

return JSON


response.failure = { resp ->
return "Request failed with status ${resp.status}"




I am putting the exact same link and credentials in the script which are working on POSTMAN and curl but it still says the connection refused and timed out. What might the error be?



1 answer

1 accepted

0 votes
Answer accepted

I was having an issue with the server. otherwise, the code is working fine.

Hi Jamshaid,


You can tell me what exactly the problem was in your server 



Like Jamshaid likes this

@Admin Jirasorry. I have been away. my server was not allowing the connections to the specified port as I remember.

Like Admin Jira likes this

Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you