0

I'm trying to get a XML from a asmx using a post.

    HttpClient client = new HttpClient();
    var request = new HttpRequestMessage(HttpMethod.Post,"https://.../esiat.asmx/RecepcionarNFSe");
    request.Content = content;
    var response = client.Send(request);
    var str = await response.Content.ReadAsStringAsync();

And I'm not getting the corret XML, its coming with this response.

enter image description here

What I'm dong wrong?

Corrent data is :

    
<tcRetornoNFSe><tcValidaGrcNFSe><tsFlgEtt>V</tsFlgEtt><tsDesOco>Estrutura do Arquivo XML OK!</tsDesOco></tcValidaGrcNFSe><tcInfRetNFSe><tsNumNot>37436</tsNumNot><tsCodVer>VMR4NBUTTW</tsCodVer><tsFlgRet>V</tsFlgRet><tsDesOco>NFSe Importado com sucesso.</tsDesOco><tsLnk>https://nfe.araxa.mg.gov.br/Valida_NFELogo_Emissao.aspx?InscricaoMunicipal=3070326219&amp;Distrito=1&amp;NumeroNota=37436&amp;CodVrfNfe=VMR4NBUTTW</tsLnk></tcInfRetNFSe></tcRetornoNFSe>


1
  • var str = await response.Content.ReadAsStringAsync(); is a string. You now have to load it into an XML document. The response is correct. Commented Jun 27, 2023 at 18:25

1 Answer 1

0

Looks like your response is HTML encoded and is located inside the tag. You can extract the content of that tag then use the HttpUtility.HtmlDecode (https://learn.microsoft.com/en-us/dotnet/api/system.web.httputility.htmldecode?view=net-7.0)

var str = await response.Content.ReadAsStringAsync();
var startTag = "<string xmlns=\"http://tempuri.org/\">";
var endTag = "</string>";
int startIndex = str.IndexOf(startTag) + startTag.Length;
int endIndex = str.IndexOf(endTag);
string innerText = str.Substring(startIndex, endIndex - startIndex);
string decodedXml = HttpUtility.HtmlDecode(innerText);

This will make your string a "xml string", I tried to scape the string if it don't work please make the adjustments necessary to find the index.

Sign up to request clarification or add additional context in comments.

2 Comments

When trying the HtmlDecoce, I got the XML but this XML is not the valid XML because the node <string xmlns="tempuri.org">
The XML content you want is inside the tag <string>, that tag is a placeholder from a C# ASMX service. Just extract the text inside that tag and Decode it, Ill update my answer. Btw next time provide Textual codes on your question xD.

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.