Hello,
I have a script in Java to upload a file to a https site with cookie context. My question : is it possible to do the same instructions with the new object HttpClient in PB ? I have put in attachment the java script that works. Thanks for your help.
here is what i need equivalence in PB :
private CloseableHttpClient httpClient = HttpClients.createDefault();
private CookieStore cookieStore = new BasicCookieStore();//Will store the session cookie
private HttpClientContext locContext = HttpClientContext.create();//Will contain the cookieStore
public int getConnection() throws ClientProtocolException, IOException {
HttpPost httpPost = new HttpPost(getUrl().concat("/j_spring_security_check"));
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpPost.setHeader("Connection", "keep-alive");
List params = new ArrayList();
params.add(new BasicNameValuePair("status", "A"));
params.add(new BasicNameValuePair("j_username", "xxxxxxx"));
params.add(new BasicNameValuePair("j_password", "yyyyyyy"));
params.add(new BasicNameValuePair("enabled", "true"));
httpPost.setEntity(new UrlEncodedFormEntity(params));
locContext.setCookieStore(cookieStore);
HttpResponse response = httpClient.execute(httpPost, locContext);
return response.getStatusLine().getStatusCode();
public void uploadFile() throws ClientProtocolException, IOException {
HttpPost uploadFile = new HttpPost(getUrl().concat("/protected/jwimportdeliveries/uploadDeliveries.do"));
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody("location", "C:/local/", ContentType.TEXT_PLAIN);
// File f = new File("C:\\Local\\Mozaik_JLB_20190124.xlsx");
// Lire_Ini file_ini = new Lire_Ini();
String file_Moza = file_ini.get_file("FILE_MOZAIK");
File f = new File(file_Moza);
builder.addBinaryBody("File", new FileInputStream(f), ContentType.APPLICATION_OCTET_STREAM, f.getName());
HttpEntity multipart = builder.build();
uploadFile.setEntity(multipart);
HttpResponse response = httpClient.execute(uploadFile, locContext);
String responseString = EntityUtils.toString(response.getEntity(), "UTF-8");
Thanks for sharing your experience with us.