Http with forceHttp1 true

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Http with forceHttp1 true

Postby JuanMartin » Mon May 01, 2023 10:49 am

Hi

In Servoy 2023.03.0, I try to send any image to Prestashop 1.7.6.7 with the Http protocol forceHttp1 true, but dosen't work

I use this code:
Code: Select all
  var config=plugins.http.createNewHttpClientConfig();
    config.forceHttp1=true;
    cliHttp = plugins.http.createNewHttpClient(config);
       var postRequest = cliHttp.createPostRequest(url);
   postRequest.addHeader('enctype', 'multipart/form-data');
   postRequest.addHeader('method', 'POST');
   postRequest.addParameter('Content-Disposition', 'form-data;name="image"');
   postRequest.addParameter('Content-Type', content);
   postRequest.addFile('image', tempFile);
   response = postRequest.executeRequest();
   
   result = utils.stringReplace(response.getResponseBody(), "><", ">\n<");


It took a long time to respond and when it does it gives this error:
ERROR com.servoy.j2db.util.Debug - response.getResponseBody API was called while response is null due to request exception: java.net.SocketTimeoutException: 50000 MILLISECONDS

Thanks
Juan Antonio Martín Pinilla
Servoy 2022.9.2 - PostgreSql 9.4
software@critenerife.com
User avatar
JuanMartin
 
Posts: 169
Joined: Tue Nov 25, 2008 9:20 pm
Location: Tenerife - Spain

Re: Http with forceHttp1 true

Postby JuanMartin » Mon May 08, 2023 8:38 pm

It is already working, in case someone needs it, it is as follows:

Code: Select all
var url = 'https://prestashop_url /api/images/products/' + product_prestahop_id;
    var config=plugins.http.createNewHttpClientConfig();
    config.forceHttp1=true;
    cliHttp = plugins.http.createNewHttpClient(config);
    var postRequest = cliHttp.createPostRequest(url);
   postRequest.addHeader('enctype', 'multipart/form-data');
   postRequest.addHeader('method', 'POST');
   postRequest.addParameter('Content-Disposition', 'form-data;name="image"');
   postRequest.addParameter('Content-Type', content);
   postRequest.addFile('image', tempFile);
   postRequest.forceMultipart(true);
   postRequest.usePreemptiveAuthentication(true);
   response = postRequest.executeRequest(_sa.presta_clientes ,"a");
   result = utils.stringReplace(response.getResponseBody(), "><", ">\n<");
Juan Antonio Martín Pinilla
Servoy 2022.9.2 - PostgreSql 9.4
software@critenerife.com
User avatar
JuanMartin
 
Posts: 169
Joined: Tue Nov 25, 2008 9:20 pm
Location: Tenerife - Spain

Re: Http with forceHttp1 true

Postby JuanMartin » Fri Jun 16, 2023 1:59 pm

Hi
I update to Servoy 2023.3.2 and forceHttp1=true dosen´t works again
With the Servoy 2023.3.1 it worked perfectly

I do not see that there has been any modification of this part in the documentation, but the truth is that with Servoy 2023.3.2 it does not work

Thanks
Juan Antonio Martín Pinilla
Servoy 2022.9.2 - PostgreSql 9.4
software@critenerife.com
User avatar
JuanMartin
 
Posts: 169
Joined: Tue Nov 25, 2008 9:20 pm
Location: Tenerife - Spain


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 14 guests