Extract XML in correct format via GET in API

Asked

Viewed 24 times

0

I am integrating a system with issuance of fiscal notes. There is an XML search method of the generated note. The return of this query (GET), is an XML. This XML I access and save in a file to use in the future.

I am getting the return and access the xml. However, it is coming with a 'wrong format'':

Example:

<?xml version="1.0" encoding="utf-8"?><string>&lt;Nfse xmlns="http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd"&gt;&lt;InfNfse&gt;&lt;Numero&gt;20213&lt;/Numero&gt;

When the right thing would be:

<Nfse xmlns="http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd"><InfNfse><Numero>20213</Numero>

It is noticeable that the < xml is being replaced by < and the < by a >

Could try to give a replace to change this.

But to get that content right now, there’s something I can do?

My xml reading function:

Try

    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12
    Dim Request As WebRequest = WebRequest.Create(url)
    Request.Credentials = CredentialCache.DefaultCredentials

    Dim auth = "Basic " & buscaAPIKey()
    Request.Headers.Add("Authorization", auth)
    Request.ContentType = "application/xml"

    Using responseStream = Request.GetResponse.GetResponseStream
        Using reader As New StreamReader(responseStream)

            Dim objResponse As Object = reader.ReadToEnd()

            Dim xml As String = objResponse.ToString.Trim

        End Using
    End Using

Catch ex As Exception
End Try

1 answer

1


It seems to me that XML is being generated wrong and treating everything as a String, as the tag <string> suggests. When it comes to generating XML, instead of treating it as separate information the API is considering everything as a single value

  • Changing Request.Contenttype = "application/xml" to "application/json" worked. Simple so rsrs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.