简体   繁体   English

使用 XML 数据时出错 内容类型 'application/xml;charset=utf-8' not supported spring

[英]Error in consuming XML data Content type 'application/xml;charset=utf-8' not supported spring

I am trying to process the request with XML Data getting error as我正在尝试使用 XML 处理请求数据获取错误为

RecurlyController.processEvents(java.lang.Object,javax.servlet.http.HttpServletRequest)]:
org.springframework.web.HttpMediaTypeNotSupportedException: 

Controller Controller

I want XML data of any structure that's why I am using Object in request我想要任何结构的 XML 数据,这就是为什么我在请求中使用 Object

@RequestMapping(value = "events", method = RequestMethod.POST, consumes = MediaType.APPLICATION_XML_VALUE)
public ModelAndView processEvents(@RequestBody Object recurlyEvent, HttpServletRequest request {
    Response response = recurlyManager.processEvents(recurlyEvent);
    return prepareModelAndView(response);
}

Http request to spring app using postman Http 请求使用 spring 应用程序使用 postman

OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/xml");
RequestBody body = RequestBody.create(mediaType, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<new_subscription_notification>\n  <account>\n    <account_code>1</account_code>\n    <username nil=\"true\">verena</username>\n    <email>verena@example.com</email>\n    <first_name>Verena</first_name>\n    <last_name>Example</last_name>\n    <company_name nil=\"true\">Company, Inc.</company_name>\n  </account>\n  <subscription>\n    <plan>\n      <plan_code>bronze</plan_code>\n      <name>Bronze Plan</name>\n    </plan>\n    <uuid>8047cb4fd5f874b14d713d785436ebd3</uuid>\n    <state>active</state>\n    <quantity type=\"integer\">2</quantity>\n    <total_amount_in_cents type=\"integer\">17000</total_amount_in_cents>\n    <subscription_add_ons type=\"array\">\n      <subscription_add_on>\n        <add_on_code>premium_support</add_on_code>\n        <name>Premium Support</name>\n        <quantity type=\"integer\">1</quantity>\n        <unit_amount_in_cents type=\"integer\">15000</unit_amount_in_cents>\n        <external_sku>pre-123</external_sku>\n        <add_on_type>fixed</add_on_type>\n        <usage_percentage nil=\"true\"></usage_percentage>\n        <measured_unit_id nil=\"true\"></measured_unit_id>\n      </subscription_add_on>\n      <subscription_add_on>\n        <add_on_code>email_blasts</add_on_code>\n        <name>Email Blasts</name>\n        <quantity type=\"integer\">1</quantity>\n        <external_sku>email-123</external_sku>\n        <unit_amount_in_cents type=\"integer\">50</unit_amount_in_cents>\n        <add_on_type>usage</add_on_type>\n        <usage_percentage nil=\"true\"></usage_percentage>\n        <measured_unit_id type=\"integer\">394681687402874853</measured_unit_id>\n      </subscription_add_on>\n      <subscription_add_on>\n        <add_on_code>donations</add_on_code>\n        <name>Donations</name>\n        <quantity type=\"integer\">1</quantity>\n        <unit_amount_in_cents nil=\"true\"></unit_amount_in_cents>\n        <add_on_type>usage</add_on_type>\n        <usage_percentage>0.6</usage_percentage>\n        <measured_unit_id type=\"integer\">394681920153192422</measured_unit_id>\n      </subscription_add_on>\n    </subscription_add_ons>\n    <activated_at type=\"datetime\">2009-11-22T13:10:38Z</activated_at>\n    <canceled_at type=\"datetime\"></canceled_at>\n    <expires_at type=\"datetime\"></expires_at>\n    <current_period_started_at type=\"datetime\">2009-11-22T13:10:38Z</current_period_started_at>\n    <current_period_ends_at type=\"datetime\">2009-11-29T13:10:38Z</current_period_ends_at>\n    <trial_started_at type=\"datetime\">2009-11-22T13:10:38Z</trial_started_at>\n    <trial_ends_at type=\"datetime\">2009-11-29T13:10:38Z</trial_ends_at>\n    <collection_method>automatic</collection_method>\n  </subscription>\n</new_subscription_notification>");
Request request = new Request.Builder()
  .url("http://a346f04e.ngrok.io")
  .method("POST", body)
  .addHeader("Content-Type", "application/xml")
  .build();
Response response = client.newCall(request).execute();

For someone looking for an answer to a similar question.对于寻找类似问题答案的人。 Removing consumes worked for me.消除消耗对我有用。

@RequestMapping(value = "events", method = RequestMethod.POST)
public ModelAndView processEvents(@RequestBody String recurlyEvent, HttpServletRequest request {
    Response response = recurlyManager.processEvents(recurlyEvent);
    return prepareModelAndView(response);
}

暂无
暂无

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

相关问题 不支持的内容类型:文本/xml; charset=utf-8 支持的有:[application/soap+xml] - Unsupported Content-Type: text/xml; charset=utf-8 Supported ones are: [application/soap+xml] org.springframework.web.HttpMediaTypeNotSupportedException:内容类型&#39;application / xml; charset = UTF-8&#39;不支持 - org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/xml;charset=UTF-8' not supported SpringBoot Post 在本地工作,但在开发区域失败,出现 415“内容类型 'application/xml;charset=UTF-8' not supported” - SpringBoot Post works locally but in dev region fails with 415 “Content type 'application/xml;charset=UTF-8' not supported” Spring Rest 应用程序中的“不支持内容类型‘application/json;charset=UTF-8’” - "Content type 'application/json;charset=UTF-8' not supported" in Spring Rest application 请求正文中的超类 - 不支持“application/xml;charset=UTF-8” - Supperclass in request body - 'application/xml;charset=UTF-8' not supported 不支持的内容类型:text / html; charset = UTF-8支持的是:Jdev中的[text / xml] - Unsupported Content-Type: text/html; charset=UTF-8 Supported ones are: [text/xml] in Jdev org.springframework.web.reactive.function.UnsupportedMediaTypeException:bodyType 不支持内容类型“text/xml;charset=UTF-8” - org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'text/xml;charset=UTF-8' not supported for bodyType 不支持内容类型 'application/json;charset=UTF-8' - Content type 'application/json;charset=UTF-8' not supported 当我尝试将 JSON 发送到 Spring 时,不支持内容类型“application/json;charset=UTF-8” - Content type 'application/json;charset=UTF-8' not supported, when i try send JSON to Spring Spring Boot - 不支持内容类型“application/x-www-form-urlencoded;charset=UTF-8” - Spring Boot - Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM