次のシナリオがあります。POSTする方法RestTemplateを使用してXML文字列
クエリ-users.xmlの
<?xml version="1.0"?>
<q:query xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3">
</q:query>
カール称賛を実行する:私はXMLで所望の応答を得る
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ファイルを持っています。 私は、JavaコードからRestTemplate
を使用して同じ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の文字列をRestTemplate
というPOSTリクエストに渡して間違っていることがありますが、それが何であるのか分かりません。
これを解決する方法はありますか?
ありがとうございました
は、サーバーのログへのアクセス権を持っていますか?私はあなたがローカルホストにアクセスしているのを見ています – TungstenX
あなたはリクエストボディにあなたのXMLを投稿していません、あなたはクエリパラメ...この投稿はあなたを助けるかもしれませんhttp://stackoverflow.com/questions/35461148/how- to-send-xml-post-requests-with-spring-resttemplate – anders