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
java.net.ConnectException: Connection refused (Connection refused)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:121)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:326)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:221)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:165)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:434)
at groovyx.net.http.HTTPBuilder.request(HTTPBuilder.java:366)
at groovyx.net.http.HTTPBuilder$request.call(Unknown Source)
at Script1264.run(Script1264.groovy:9)
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 groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import groovyx.net.http.ContentType
import static groovyx.net.http.Method.*
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?
thanks
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
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Admin Jirasorry. I have been away. my server was not allowing the connections to the specified port as I remember.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.