使用Apache HttpClient的java Http 400 PUT请求
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请求,并毫无问题地获得响应
有人能发现是什么导致了这个糟糕的请求吗
编辑:可以在这里看到新的XML文件:http://pastebin.com/RbBPwCbH
newXML中的格式是正确的,它与我从prestashop获得的get响应格式完全对应
共 (0) 个答案