我有以下情形。我有一个XML文件:如何使用RestTemplate POST XML字符串
查询users.xml中
<?xml version="1.0"?>
<q:query xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3">
</q:query>
当执行卷曲称道:
curl.exe --user administrator:5ecr3t -H "Content-Type: application/xml" -X POST http://localhost:8080/midpoint/ws/rest/users/search -d @C:\Users\user\query-users.xml
我得到XML所需的响应。 我试图做使用RestTemplate
从Java代码相同的POST请求:
try{
StringBuilder builder = new StringBuilder();
builder.append("http://localhost:8080/midpoint/ws/rest/users/search");
builder.append("?query=");
builder.append(URLEncoder.encode("<?xml version=\"1.0\"?><q:query xmlns:q=\"http://prism.evolveum.com/xml/ns/public/query-3\"></q:query>"));
URI uri = URI.create(builder.toString());
restOperations.postForEntity(uri, new HttpEntity<String>(createHeaders("username", "pass")), String.class);
logger.info(response);
}catch(Exception e){
logger.info(e.getMessage());
}
}
我得到Internal Servel Error
。 有一件事是我做错了将XML字符串传递给POST请求与RestTemplate
,但我没有搞清楚它是什么。
有没有办法解决这个问题?
感谢
你有访问服务器的日志?我看到你正在访问本地主机 – TungstenX
你没有发布你的xml在请求正文中,你发送它作为查询参数...本文可能会帮助你http://stackoverflow.com/questions/35461148/how-待送的XML-后请求与 - 弹簧resttemplate – anders