简体   繁体   English

带有POST和xml的Cisco ISE REST HttpUrlConnection 400错误请求

[英]Cisco ISE REST HttpUrlConnection 400 Bad Request with POST and xml in body

I'm currently working on a program that takes 4 values(MAC, Policy, IdentityGroup and description) from a csv file and writes them to a Cisco ISE as Endpoint. 我目前正在研究一个程序,该程序从csv文件中获取4个值(MAC,策略,IdentityGroup和描述),并将它们作为端点写入Cisco ISE。

The user credentials and URL are aquired via a little GUI. 用户凭证和URL是通过一个小的GUI来获取的。

First I'm checking if the IdentityGroups given in the file are valid via a GET Request that works just fine and return a Map of Group IDs mapped to Groupnames. 首先,我通过一个可以正常工作的GET请求来检查文件中提供的IdentityGroups是否有效,并返回映射到Groupnames的Group ID映射。

Then I try to create the Endpoint by sending a POST Request with the required information as XML in the Body: 然后,我尝试通过在主体中发送带有XML所需信息的POST请求来创建端点:

URL readURL = new URL(url.getProtocol() + "://" + url.getHost() + ":" + 

url.getPort() + "/ers/config/Endpoint");
HttpURLconnection con;
con = (HttpURLConnection) readURL.openConnection();
con.setRequestProperty("Authorization","Basic "+ Base64.getEncoder().encodeToString((username + ":" + password.getBytes("utf-8")));
con.setRequestProperty("Accept", "application/vnd.com.cisco.ise.identity.Endpoint.1.0.xml");
con.setRequestProperty("Accept-Charset","utf-8");
con.setRequestProperty("Content-Type","application/vnd.com.cisco.ise.identity.Endpoint.1.0+xml");
con.setDoOutput(true)
con.setDoInput(true);
con.connect();

System.out.println("All Properties set.");

OutputStreamWriter writer = new OutputStreamWriter(con.getOutputStream(), "UTF-8");

System.out.println("Got Outputstream.");

System.out.println("The entry to write: "+e.toString());

writer.write("<ns3:endpoint name=\"" + e.getMAC()
        + "\" id=\"12341234-12341234-asdasdf-12341\" description=\"" + e.getDescription()
        + "\" xmlns:ns2=\"ers.ise.cisco.com\" xmlns:ns3=\"identity.ers.ise.cisco.com\"><groupId>"
        + groupIDs.get(e.getEndpointIdentifyGroup())    
        + "</groupId><identityStore></identityStore><identityStoreId></identityStoreId><mac>" + e.getMAC()      
        + "</mac><portalUser></portalUser><profileId></profileId><staticGroupAssignment>true</staticGroupAssignment><staticProfileAssignment>false</staticProfileAssignment>");

writer.flush();

System.out.println("MAC " + e.getMAC() + " was sent.");
writer.close();

System.out.println("All entries were written.");

System.out.println(con.getResponseMessage());

Console Output: 控制台输出:

All Properties set.
Got Outputstream.
The entry to write: CSVEntry [endpointPolicy=StringProperty [value: test], endpointIdentifyGroup=StringProperty [value: test], MAC=StringProperty [value: 11:11:11:11:11:11], description=StringProperty [value: tes>_phe]]
MAC 11:11:11:11:11:11 was sent.
All entries were written.
Bad Request
java.io.IOException: Server returned HTTP response code: 400 for URL: https://193.186.11.135:9060/ers/config/Endpoint
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
.....
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: https://193.186.11.135:9060/ers/config/Endpoint
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1839)
....

I've tried multiple things such as different headers, writing in multiple lines, checking the values like 500 times but I have no idea why I am getting a 400 Bad Request Response. 我已经尝试了多种操作,例如不同的标题,多行编写,检查了500次之类的值,但我不知道为什么会收到400 Bad Request Response。

The other thing that I tried aswell is checking if the Request would be correct by using Postman and sending the POST Request with the exact same headers and the exact same body to the Server and it works (getting 201 Created and it shows in DB). 我还尝试过的另一件事是通过使用Postman并将带有完全相同的标头和完全相同的正文的POST请求发送到服务器来检查请求是否正确,并且工作正常(获得201创建并在DB中显示)。

I hope someone can help me as I don't know what to do, I was googling around checking for solutions but all that I tried didn't work. 我希望有人可以帮助我,因为我不知道该怎么办,我一直在寻找解决方案,但是我尝试的所有方法都没有用。

Thanks in advance for your much appreciated help. 在此先感谢您的帮助。

OKay, I found the mistake and I'm ashamed. 好吧,我发现了错误,我很ham愧。 I forgot to close the xml body with 我忘了用来关闭xml正文

</ns3:endpoint>

so it didn't work. 所以没有用 It is now working perfectly fine. 现在工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM