Connection refused when trying to send POST request

Mamikon Papikyan June 1, 2020

I use script-runner to send POST request in the server (http://localhost:5001), but I get "Connection refused". When i tried send it another(https://httpbin.org/post) server it worked perfectly, but don't know why it doesn't work in this server? Maybe the problem in the port??? Any suggestions will be great. Here is my groovy script:

 

import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.json.JsonSlurper;
import groovy.json.StreamingJsonBuilder;
import org.apache.commons.codec.binary.Base64;

//Debug
def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)
//Body

 

def body_req = [
"command" : [
"gdp", "list", "test/p2"
],
]


//def baseURL = "https://httpbin.org/post";

def baseURL = "http://localhost:5001";

URL url;

url = new URL(baseURL);

HttpURLConnection connection = url.openConnection() as HttpURLConnection;
connection.requestMethod = "POST"
connection.doOutput = true
connection.setRequestProperty("Content-Type", "application/json")
connection.outputStream.withWriter("UTF-8") { new StreamingJsonBuilder(it, body_req) }
connection.connect();

log.info("json_body="+body_req+" URL="+url+" Status="+connection.getResponseCode() as String)

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events