我通过这个在线转换器UTF8运行了一些输入文本
我将输出输入到我的API中,该API对其进行解码并进行进一步处理。
@RequestMapping(value = "/highlight", method = RequestMethod.POST)
@ResponseBody
public String highlightTester(@RequestBody String programInput) throws UnsupportedEncodingException {
byte[] decoded = Base64.getMimeDecoder().decode(programInput);
String result = new String(decoded, StandardCharsets.UTF_8);
当我记录这些信息时,我不断得到一个奇怪的角色..
{
"code": "ICAgICAgICAvLyBTaW1wbGUgdXNlIFB5Z21lbnRzIGFzIHlvdSB3b3VsZCBpbiBQeXRob24NCiAgICAgICAgaW50ZXJwcmV0ZXIuZXhlYygiZnJvbSBweWdtZW50cyBpbXBvcnQgaGlnaGxpZ2h0XG4iDQogICAgICAgICAgICAgICAgKyAiZnJvbSBweWdtZW50cy5sZXhlcnMgaW1wb3J0IFB5dGhvbkxleGVyXG4iDQogICAgICAgICAgICAgICAgKyAiZnJvbSBweWdtZW50cy5mb3JtYXR0ZXJzIGltcG9ydCBIdG1sRm9ybWF0dGVyXG4iDQogICAgICAgICAgICAgICAgKyAiZm9ybWF0dGVyID0gSHRtbEZvcm1hdHRlcihzdHlsZT0nbW9ub2thaScsIg0KICAgICAgICAgICAgICAgICsgIiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsaW5lbm9zPUZhbHNlLCINCiAgICAgICAgICAgICAgICArICIgICAgICAgICAgICAgICAgICAgICAgICAgICAgbm9jbGFzc2VzPVRydWUsIg0KICAgICAgICAgICAgICAgICsgIiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjc3NjbGFzcz0nJywiDQogICAgICAgICAgICAgICAgKyAiICAgICAgICAgICAgICAgICAgICAgICAgICAgIHByZXN0eWxlcz0nbWFyZ2luOiAwJykiDQogICAgICAgICAgICAgICAgKyAiXG5yZXN1bHQgPSBoaWdobGlnaHQoY29kZSwgUHl0aG9uTGV4ZXIoKSwgZm9ybWF0dGVyKSIpOw0KDQogICAgICAgIC8vIEdldCB0aGUgcmVzdWx0IHRoYXQgaGFzIGJlZW4gc2V0IGluIGEgdmFyaWFibGUNCiAgICAgICAgbG9nLmluZm8oaW50ZXJwcmV0ZXIuZ2V0KCJyZXN1bHQiLCBTdHJpbmcuY2xhc3MpKTsNCiAgICAgICAgcmV0dXJuIGludGVycHJldGVyLmdldCgicmVzdWx0IiwgU3RyaW5nLmNsYXNzKTs="
}
....#1e0010">�</span><span style="color: #f92672">^</span>....
现在,即使我使用不同的编码器,我也会传入输入的每种输入类型。为什么会这样?
r�^wefwefwef
我正在使用 Java Spring Boot 来运行我的API,所以想知道我是否通过Postman传递这个内容会为我的调用添加一些额外的风格。
答案 0 :(得分:1)
您将整个请求正文传递给base64解码器。由于请求体不仅包含base64编码的字符串,还包含JSON标记,因此解码将失败或导致意外输出。
要修复,请: