【发布时间】:2021-07-14 10:31:12
【问题描述】:
我正在尝试读取 json 并将其以 XML 的形式发送回服务器。我能够成功读取 json,但我需要从端点中读取的内容发送 xml
URL url = new URL("https://xxxx.xxx/xxxx/post");
HttpURLConnection http = (HttpURLConnection)url.openConnection();
http.setRequestMethod("POST");
http.setDoOutput(true);
http.setRequestProperty("Content-Type", "application/xml");
http.setRequestProperty("Accept", "application/xml");
String data = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Request>\n <Login>login</Login>\n
<Password>password</Password>\n</Request>";
byte[] out = data.getBytes(StandardCharsets.UTF_8);
OutputStream stream = http.getOutputStream();
stream.write(out);
System.out.println(http.getResponseCode() + " " + http.getResponseMessage());
http.disconnect();
目前我正在对字符串数据进行硬编码,但如果我点击此端点我想发送位于我的休息端点 http://localhost:8080/login 中的数据我得到一个 XML
<ArrayList>
<item>
<Login>1000<Login>
<Password>Pwd<Password>
</item>
</ArrayList>
如何读取此端点并用作字符串数据
【问题讨论】:
标签: java spring spring-boot