1

There are a hundred questions like this but I couldn't find any working answer to my question.

With curl I have a working request, response is 201: created:

curl -i -X POST https://username:APITOKEN@jenkins-server/job/jobName/buildWithParameters?token=TOKEN -H "Jenkins-Crumb:xxxx"

However, if I try to replicate the same request in Java, I get a 403 No valid crumb was included in the request. CSRF is activated (with proxy compatibility enabled).

My Java implementation (using org.apache.httpcomponents:httpcore v.4.4.9):

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;

HttpClient client = HttpClients.createDefault();
String url = "https://username:" + apiToken + "@" + "jenkins-server/job/jobName/buildWithParameters?token=TOKEN";
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Jenkins-Crumb", "xxxx");
HttpResponse response = client.execute(httpPost);

What am I missing?

EDIT I have tried with other Java libraries as well (Unirest, OkHttp) resulting in the same response code 403. Tried also with Python (requests library) where it works like a charm:

requests.request("POST", "https://username:ApiToken@jenkins-server/job/jobname/buildWithParameters", data="", headers={"Jenkins-Crumb": "xxx"}, params={"token":"TOKEN"})
zxiiro
  • 92
  • 5
Damian
  • 79
  • 1
  • 11

0 Answers0