即使我使用 MediaType.APPLICATION_XML_VALUE,application/xml 仍不受支持的媒体类型

发布于 2025-01-11 03:13:46 字数 1377 浏览 0 评论 0原文

我通过 postman 运行以下curl 命令。

curl --location --request POST 'http://localhost:8080/cefcy/get_eD_XML' \
--header 'Content-Type: application/xml' \
--header 'Cookie: JSESSIONID=800845E7C67023C8B0B3C8CF7B6EB0E4' \
--data-raw '<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:epsos="urn:epsos-org:ep:medication" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><typeId extension="POCD_HD000040" root="2.16.840.1.113883.1.3"/></ClinicalDocument>'

在我的 java spring boot 项目中,我有以下内容:

@SessionScope
@RestController
public class eD  extends Ctr  {
    private final static Logger LOG = LoggerFactory.getLogger(eD.class);

@RequestMapping(value = "/get_eD_XML", method=RequestMethod.POST,
        produces = {MediaType.APPLICATION_JSON_VALUE},consumes={MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE})
protected String eD_XML(@RequestBody ObjectNode model,HttpServletRequest request, 
        HttpServletResponse response) throws ServletException, IOException, NoSuchAlgorithmException {
    
    String eD = IOUtils.toString(request.getReader()); //trying to read the xml file
   }
}

但是,在邮递员中,我得到以下响应:

{
    "timestamp": "2022-03-02T14:12:30.070+00:00",
    "status": 415,
    "error": "Unsupported Media Type",
    "message": "",
    "path": "/cefcy/get_eD_XML"
}

I run the following curl command through postman.

curl --location --request POST 'http://localhost:8080/cefcy/get_eD_XML' \
--header 'Content-Type: application/xml' \
--header 'Cookie: JSESSIONID=800845E7C67023C8B0B3C8CF7B6EB0E4' \
--data-raw '<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:epsos="urn:epsos-org:ep:medication" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><typeId extension="POCD_HD000040" root="2.16.840.1.113883.1.3"/></ClinicalDocument>'

In my java spring boot project I have the following:

@SessionScope
@RestController
public class eD  extends Ctr  {
    private final static Logger LOG = LoggerFactory.getLogger(eD.class);

@RequestMapping(value = "/get_eD_XML", method=RequestMethod.POST,
        produces = {MediaType.APPLICATION_JSON_VALUE},consumes={MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE})
protected String eD_XML(@RequestBody ObjectNode model,HttpServletRequest request, 
        HttpServletResponse response) throws ServletException, IOException, NoSuchAlgorithmException {
    
    String eD = IOUtils.toString(request.getReader()); //trying to read the xml file
   }
}

However, in postman I get the following response:

{
    "timestamp": "2022-03-02T14:12:30.070+00:00",
    "status": 415,
    "error": "Unsupported Media Type",
    "message": "",
    "path": "/cefcy/get_eD_XML"
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪漫之都 2025-01-18 03:13:46

感谢 MI的博客 pom.xml中需要以下依赖。

<dependency>
  <groupId>com.fasterxml.jackson.dataformat</groupId>
  <artifactId>jackson-dataformat-xml</artifactId>
  <version>2.11.0</version>
</dependency>

Thanks to MI's blog the following dependency is needed in pom.xml.

<dependency>
  <groupId>com.fasterxml.jackson.dataformat</groupId>
  <artifactId>jackson-dataformat-xml</artifactId>
  <version>2.11.0</version>
</dependency>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文