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)
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.