HTTP Error 406 using Rest Delphi components with XML return

Asked

Viewed 1,095 times

2

I am trying to consult an NFS-e with the REST components in the XE7, in the queries of type Json I could normally, but when the return is of type XML it gives error 406, I tried to send the Accept and Content-Type in the header but also not solved, Has anyone been through this? need to do some differentiated treatment when the return is XML?

Follows the code:

  RESTRequest.ResetToDefaults;
  RESTClient.ResetToDefaults;
  RESTResponse.ResetToDefaults;

  RESTClient.BaseURL := 'https://nfps-e-hml.pmf.sc.gov.br/api/v1/consultas/notas/xml/126564/4554566';

  RESTClient.Authenticator := nil;

  RESTRequest.Method := TRESTRequestMethod.rmGET;

  RESTRequest.Execute;

  Memo1.Clear;
  Memo1.Lines.Text := RESTResponse.Content;

Error: inserir a descrição da imagem aqui

  • Add an error print, 406 can be very generic by the fact of RESTClient be based on Indy.

  • I put all the return

2 answers

2


Before the Execute define a Accept suitable to the file you are trying to access:

RESTRequest.Accept := 'text/xml';
RESTRequest.Execute;

Perform the tests and report the result.

  • It worked kk, had tested everything and had not worked, thank you very much :)

-1

Might also work

RESTRequest.Accept := 'application/json';
RESTRequest.Execute;

Browser other questions tagged

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