0
public static void putRequestToPrestashop(String id,String newXML) throws IOException{

    final String login = "VNIPG9YYCESFNK0CLXQNIDBJR24WQZ5E";
    final String password ="";


    //DefaultHttpClient has been depricated, use HttpClientBuilder instead.
    HttpClient httpClient = HttpClientBuilder.create().build();

    httpClient.getCredentialsProvider().setCredentials(
                    new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, "basic"),
                    new UsernamePasswordCredentials(login, password));


    HttpPut putRequest = new HttpPut("http://127.0.0.1:4001/prestashop/api/products/"+id);
    //System.out.println("putREQ:  "+putRequest);

    StringEntity input = new StringEntity(newXML);
    input.setContentType("text/xml");

    putRequest.setEntity(input);
    HttpResponse response = httpClient.execute(putRequest);

    System.out.println(response);
    httpClient.getConnectionManager().shutdown();

}

The error I get is:

HTTP/1.1 400 Bad Request [Date: Fri, 05 Jul 2013 08:49:39 GMT, Server: Apache/2.2.15 (Win32) PHP/5.3.2, Vary: Host, X-Powered-By: PrestaShop Webservice, Access-Time: 1373014179, PSWS-Version: 1.5.4.1, Execution-Time: 0.072, Content-Length: 241, Connection: close, Content-Type: text/xml;charset=utf-8]

The username and password are most definitely correct and I can access the api locally without problems. Also I can send a GET request to the api and get the response without problems.

Can anyone spot what seems to cause the Bad Request???

EDIT: the newXML file can be seen here: http://pastebin.com/RbBPwCbH

The format in the newXML is correct, it corresponds exactly to the get response format I get from prestashop.

JCaptain
  • 51
  • 1
  • 6
fusi0n
  • 1,059
  • 3
  • 12
  • 21
  • could it be that the request body is not in the right format or is missing some required data? what is the content of your ``newXML`` variable? – benjiman Jul 05 '13 at 09:01
  • Does PrestaShop log more information? – Jasper Jul 05 '13 at 09:05
  • Unfortunately I could not find any log info on the PrestaShop side. – fusi0n Jul 05 '13 at 09:24
  • 1
    @fusi0n check out the following link to turn on error logging: http://mypresta.eu/en/art/developer/how-to-turn-on-error-log-error-reporting-in-prestashop.html – Jasper Jul 05 '13 at 09:46
  • Thank you for that, I turned it on, but nothing shows up in the log when I send the request. – fusi0n Jul 05 '13 at 09:54
  • 1
    @fusi0n maybe you could check out your `ModSecurity` settings (http://forge.prestashop.com/browse/PSCFV-7428) – Jasper Jul 05 '13 at 11:01
  • Thank you for that info, that seems to be the issue probably because, as I said, GET request work fine and PUT request are the ones that mod_security does not like. Now the problem is how to change that. I could not find anything on my apache server with the name: mod_security or security or modsecurity. Neither did I find anything in the apache configuration file... Does anyone have any experience with this? – fusi0n Jul 05 '13 at 11:41
  • @fusi0n I'm no expert on this matter, but perhaps the following can help: http://www.askapache.com/htaccess/modsecurity-htaccess-tricks.html#Disabling_mod_security_conditionally_IP – Jasper Jul 05 '13 at 12:26

0 Answers0