0

I am trying to set up XML validation in Azure api management policy. I have the following policy set up. The purchase order schemas is there in the schemas section:

<inbound>
      <base />
      <validate-content unspecified-content-type-action="detect" max-size="1048576" size-exceeded-action="ignore">           
          <content type="application/xml" validate-as="xml" action="prevent" schema-id="PurchaseOrder" />
      </validate-content>
  </inbound>

I am testing out the api. In the header I have Content-Type: application/xml. The body is raw. Screenshot below: enter image description here

<?xml version="1.0" encoding="UTF-8"?>
<PurchaseOrder xmlns="http://tempuri.org/PurchaseOrderSchema.xsd">
    <ShipTo country="US">
        <name>John Smith</name>
        <street>123 Maple Street</street>
        <city>Springfield</city>
        <state>IL</state>
        <zip>62704</zip>
    </ShipTo>
    <ShipTo country="US">
        <name>Jane Doe</name>
        <street>456 Oak Avenue</street>
        <city>Chicago</city>
        <state>IL</state>
        <zip>60616</zip>
    </ShipTo>
    <BillTo country="US">
        <name>Acme Corp</name>
        <street>789 Pine Road</street>
        <city>Naperville</city>
        <state>IL</state>
        <zip>60540</zip>
    </BillTo>
</PurchaseOrder>

I get the following saying that:

Unspecified content type application/xml is not allowed.

I have imported the schemas for purchaseOrder in the apim schemas section:

{
    "name": "application/xml",
    "type": "RequestBody",
    "validationRule": "Unspecified",
    "details": "Unspecified content type application/xml is not allowed.",
    "action": "Detected"
}

enter image description here

However, I do see the headers content type xml in the trace inspection.

enter image description here

10
  • A server will accept only types that is programmed to accept. The server you are connecting to does not accept application/xml. Unless you can reprogram the server there is nothing you can do to fix the issue. Commented Sep 2 at 17:09
  • @jdweng thanks for reply. However this is not the backend server that is is doing it. It's the policy section Commented Sep 3 at 7:35
  • content type application/xml is an http header and should be configure in the policy like this : learn.microsoft.com/en-us/azure/api-management/… Commented Sep 3 at 9:14
  • However, the headers does have a content type xml. I have uploaded the image from the inbound section of trace. The headers has content-type xml Commented Sep 3 at 12:18
  • Not in the Policy like the link I provided. Commented Sep 3 at 20:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.