Saltar a contenido

XML

Sí se desea enviar datos con XML, el ejemplo queda de la siguiente manera:

Recuerda

Tenga en cuenta que este módulo no pretende convertirse en un cliente de XML/SOAP.

from app.common.http.xml import XMLApi
from typing import Optional, Any
...

BASE_URL = "https://www.w3schools.com/xml/tempconvert.asmx"

body = """<?xml version="1.0" encoding="utf-8"?><soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"><soap12:Body><CelsiusToFahrenheit xmlns="https://www.w3schools.com/xml/"><Celsius>20</Celsius></CelsiusToFahrenheit></soap12:Body></soap12:Envelope>"""

xml_api = XMLApi()
headers = {"Content-Type": "application/soap+xml; charset=utf-8"}

result: Optional[dict[str, Any]] = xml_api.post(BASE_URL, body, headers, True)

Para tener en cuenta

La clase XMLApi, solo maneja el método post.

para manejar la respuesta se utiliza xml.etree.ElementTree, más información por aquí

Lectura recomendada