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.