Error when ordering with PagSeguro API

2

When I try to create the payment, I get the following error. I'm using the following package: link

  

Additional information: For security reasons, the DTD is prohibited   in this XML document. To enable processing of the DTD, set the   DtdProcessing property in XmlReaderSettings as Parse, and pass the   settings for the XmlReader.Create method.

I'm using a test code offered by Cigano in this topic :

The exception is raised in the following line:

var paymentRedirectUri = payment.Register(credentials);

I'm also using the sandbox environment of PagSeguro, and I already checked the credentials and URL sent (before I was giving 401 error).

I can work around the error described above by editing the API code in the following code block:

XmlReaderSettings settings = new XmlReaderSettings();
settings.ProhibitDtd = false;
using (XmlReader reader =     XmlReader.Create(response.GetResponseStream(), settings))
{
  //Codigo pagseguro
}

However, when I make this change, I get the following error when the API reads XML

  

Additional information: Invalid character in the provided encoding.   Line 20, position 48.

    
asked by anonymous 05.11.2014 / 23:59

1 answer

0

Invalid character, this sounds like an XML that works with ANSI (or iso-8859-1 / window-1252 ) but end up returning data with UTF-8 characters, it's just a theory, but maybe you should check the encodings returned by XML . To do this check try to analyze the contents of response.GetResponseStream() .

Note that if your XML uses UTF-8 (or other UNICODE encoding) and the header does not have something like <?xml charset="UTF-8" ?> it is very likely that this error will occur.

If the document has equivalent characters of latin1 and there is no charset set to iso-8859-1 or windows-1252 , this error can also occur.

By analyzing the user code Cigano, I did not find anything referring to the XmlReader that you mentioned, so I will assume that this is your application.

An alternative solution would be to use this property:

public bool CheckCharacters { get; set; }

Setting to false XmlReaderSettings.CheckCharacters will turn off character checking.

Follow the documentation:

link

    
24.12.2014 / 17:07