Beak2k
Beak2k

Reputation: 55

Jenkins pipeline not able to execute the HttpClient.execute(HttpPost)

My groovy config in Jenkins pipeline:

HttpUriRequest postRequestLogin = new HttpPost();

List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("j_username", "${user}"))
urlParameters.add(new BasicNameValuePair("j_password", "${pass}"))
postRequestLogin.setEntity(new UrlEncodedFormEntity(urlParameters))

CloseableHttpResponse responseLogin = httpClient.execute(postRequestLogin)

I got the following error:

No signature of method: org.apache.http.impl.client.InternalHttpClient.execute() is applicable for argument types: (org.apache.http.client.methods.HttpPost) values: [org.apache.http.client.methods.HttpPost@eb47360] Possible solutions: execute(org.apache.http.client.methods.HttpUriRequest), execute(org.apache.http.client.methods.HttpUriRequest, org.apache.http.client.ResponseHandler), execute(org.apache.http.HttpHost, org.apache.http.HttpRequest), execute(org.apache.http.client.methods.HttpUriRequest, org.apache.http.protocol.HttpContext), execute(org.apache.http.HttpHost, org.apache.http.HttpRequest, org.apache.http.client.ResponseHandler), execute(org.apache.http.client.methods.HttpUriRequest, org.apache.http.client.ResponseHandler, org.apache.http.protocol.HttpContext)

Upvotes: 0

Views: 687

Answers (1)

Sam
Sam

Reputation: 2882

Alternative way to make the request:

    URL url = url_string.toURL()
    // Create authorization header format using Base64 encoding
    String userpass = username + ":" + apiKey;
    String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());
    // Open connection
    URLConnection connection = url.openConnection()

    connection.setRequestProperty ("Authorization", basicAuthString())
    connection.setRequestMethod("POST")
    connection.doOutput = false;

    // Open input stream
    InputStream inputStream = connection.getInputStream()
    // Close the stream
    inputStream.close()

    return connection.getResponseCode()

Upvotes: 1

Related Questions