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();

}

我得到的错误是:

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]

用户名和密码绝对正确,我可以毫无问题地在本地访问 api。我也可以向 api 发送 GET 请求并毫无问题地获得响应。

谁能发现似乎导致错误请求的原因???

编辑: newXML 文件可以在这里看到:http://pastebin.com/RbBPwCbH

newXML 中的格式是正确的,它与我从 prestashop 获得的获取响应格式完全对应。

4

0 回答 0