• 0
Jahn Carlos

Retorno de requisição em HTML no DELPHI

Question

Olá,
Estou fazendo uma requisição para listar as categorias no Mercado Livre em Delphi usando os componentes do RESTClient.

O problema ocorre quando eu vou receber a resposta do GET; Ela vem como um código HTML.

<!DOCTYPE html><!--if lt IE 7 ]><html class="ie ie6" lang="en">--><!--if IE 7 ]><html class="ie ie7" lang="en">--><!--if IE 8 ]><html class="ie ie8" lang="en">--><!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]--><head><meta charset="utf-8"><title>Countries</title><meta name="description" content="Retrieves countries information"><meta name="author" content="MercadoLibre"><link rel="stylesheet" href="/apidoc/assets/css/pygments.css"><link rel="stylesheet" href="/apidoc/assets/css/api_options.css"></head><body><div class="content"><h1>Countries</h1><h2>Retrieves countries information</h2><nav class="tabs"><ul><li><a tabindex="1" href="#json">Results</a></li><li><a tabindex="2" href="#options">API Documentation</a></li></ul></nav><div class="tabcontents"><section id="json"><p class="expand-controls"><a id="collapse-all">collapse all</a><a id="expand-all">expand all</a></p><div class="highlight"><pre>
<span class="p">[<span class="collapsible">
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/AR">"AR"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Argentina"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_AR"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/ARS">"ARS"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/BO">"BO"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Bolivia"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_BO"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/BOB">"BOB"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/BR">"BR"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Brasil"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"pt_BR"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/BRL">"BRL"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/CL">"CL"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Chile"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_CL"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/CLP">"CLP"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/CN">"CN"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"China"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"zh_CN"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/CNY">"CNY"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/CO">"CO"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Colombia"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_CO"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/COP">"COP"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/CR">"CR"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Costa Rica"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_CR"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/CRC">"CRC"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/CBT">"CBT"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Cross Border Trade"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_AR"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/ARS">"ARS"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/EC">"EC"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Ecuador"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_EC"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/USD">"USD"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/SV">"SV"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"El Salvador"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_SV"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/USD">"USD"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/GT">"GT"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Guatemala"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_GT"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/GTQ">"GTQ"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/HN">"HN"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Honduras"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_HN"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/HNL">"HNL"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/MX">"MX"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Mexico"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_MX"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/MXN">"MXN"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/NI">"NI"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Nicaragua"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_NI"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/NIO">"NIO"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/PA">"PA"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Panamá"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_PA"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/USD">"USD"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/PY">"PY"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Paraguay"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_PY"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/PYG">"PYG"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/PE">"PE"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Peru"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_PE"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/PEN">"PEN"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/PT">"PT"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Portugal"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"pt_PT"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/EUR">"EUR"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/PR">"PR"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Puerto Rico"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_PR"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/USD">"USD"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/GB">"GB"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Reino Unido"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"en_GB"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/GBP">"GBP"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/DO">"DO"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"República Dominicana"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_DO"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/DOP">"DOP"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/UY">"UY"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Uruguay"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_UY"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/UYU">"UYU"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/VE">"VE"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Venezuela"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_VE"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/VEF">"VEF"</a></span>
  </span>}</span>,
  <span class="p">{<span class="collapsible">
    <span class="nt">"id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/classified_locations/countries/COL">"COL"</a></span>,
    <span class="nt">"name"</span><span class="p">:</span> <span class="s2">"newCOL"</span>,
    <span class="nt">"locale"</span><span class="p">:</span> <span class="s2">"es_COL"</span>,
    <span class="nt">"currency_id"</span><span class="p">:</span> <span class="s2"><a class="navigation-link" href="/currencies/COLS">"COLS"</a></span>
  </span>}</span>
</span>]</span></pre></div></section><section id="options"><dl class="glossary"><dt class="collapsable">Allowed methods</dt><dd><dl> <dd>Retrieves countries information</dd><dd><dl><dt>GET</dt><dd>/classified_locations/countries</dd></dl></dd></dl></dd><dt class="collapsable">Attributes</dt><dd><dl><dt class="attribute">currency_id</dt><dd>Currency ID</dd><dt class="attribute">id</dt><dd>Country ID</dd><dt class="attribute">locale</dt><dd>Language ID</dd><dt class="attribute">name</dt><dd>Country name</dd></dl></dd><dt class="collapsable">Related resources</dt><dd><dl><dd>currencies</dd><dd>countries</dd></dl></dd></dl></section></div></div><footer>Copyright &copy; 2018 - MercadoLibre</footer><script src="/apidoc/assets/js/api_options.js"></script><script src="/apidoc/assets/js/require-jquery.js"></script><script>var collapseAll = $('.highlight pre span:first').html()[0]=='{';
$('.collapsible:not(:first)').each(function(index, e) {
 var e = $(e);
 if(e.children().length > 0) {
  var expander = $('<a class="expander"></a>');
   expander.click(function() {
    e.trigger('expand');
   });
   e.before(expander);
  var collapser = $('<a class="collapser"></a>');
   collapser.click(function() {
    e.trigger('collapse');
   });
   e.parent().prepend(collapser);
   
  e.on('collapse', null, null, function() {
   collapser.hide();
   expander.show();
   $(this).hide();
   return false;
  });
  e.on('expand', null, null, function() {
   expander.hide();
   collapser.show();
   $(this).show();
   return false;
  });
  if(collapseAll) {
   e.trigger('collapse');
  } else {
   e.trigger('expand');
  }
 }
});
$(document).ready(function() {
 if(collapseAll) {
  $('#expand-all').css("display","inline-block");
  $('#collapse-all').css("display","none");
 } else {
  $('#collapse-all').css("display","inline-block");
  $('#expand-all').css("display","none");
 }
 
 $('#collapse-all').click(function() {
  $('.collapsible:not(:first)').trigger('collapse');
  $(this).css("display","none");
  $('#expand-all').css("display","inline-block");
 });
 $('#expand-all').click(function() {
  $('.collapsible:not(:first)').trigger('expand');
  $(this).css("display","none");
  $('#collapse-all').css("display","inline-block");
 });
 
 
 $(".collapsable").each (function (index, e) {
  var content;
  var next = e.nextSibling;
  while (next) {
   var dl = next.querySelector("dl");
   if (next.tagName == "DD" && dl) {
    content = dl;
    
    content.parentElement.insertBefore(document.createTextNode("\u00a0"), content);
    break;
   }
   
   next = next.nextSibling;
  }
  
  if (content) {
   e.content = content;
  }
  
  $(e).on ("click", function () {
   $(this).toggleClass("collapsed");
   $(this.content).toggleClass("hidden");
  });
 });
});
</script></body><!-- </html>-->

Já setei todas as propriedades do RESTClient, RESTRequest e RESTResponse para retornar 'application/json'. mesmo assim ela só retorna a resposta acima.

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0
3 hours ago, Jahn Carlos said:

https://api.mercadolibre.com/sites/MLB/categories

 

é o de requisição de Categorias mesmo, publico.

Vc deve estar usando um componente de web. Última vez que mexi com o Delphi foi em... 2007.
Eu usei o SDK PHP e o cURL para PHP, os resultados foram:

SDK PHP:

Array
(
    [body] => Array
        (
            [0] => stdClass Object
                (
                    [id] => MLB5672
                    [name] => Acessórios para Veículos
                )

            [1] => stdClass Object
                (
                    [id] => MLB1499
                    [name] => Agro, Indústria e Comércio
                )

            [2] => stdClass Object
                (
                    [id] => MLB1403
                    [name] => Alimentos e Bebidas
                )

            [3] => stdClass Object
                (
                    [id] => MLB1071
                    [name] => Animais
                )

            [4] => stdClass Object
                (
                    [id] => MLB1367
                    [name] => Antiguidades
                )

            [5] => stdClass Object
                (
                    [id] => MLB1368
                    [name] => Arte e Artesanato
                )

            [6] => stdClass Object
                (
                    [id] => MLB1384
                    [name] => Bebês
                )

            [7] => stdClass Object
                (
                    [id] => MLB1246
                    [name] => Beleza e Cuidado Pessoal
                )

            [8] => stdClass Object
                (
                    [id] => MLB1132
                    [name] => Brinquedos e Hobbies
                )

            [9] => stdClass Object
                (
                    [id] => MLB1430
                    [name] => Calçados, Roupas e Bolsas
                )

            [10] => stdClass Object
                (
                    [id] => MLB1039
                    [name] => Câmeras e Acessórios
                )

            [11] => stdClass Object
                (
                    [id] => MLB1743
                    [name] => Carros, Motos e Outros
                )

            [12] => stdClass Object
                (
                    [id] => MLB1574
                    [name] => Casa, Móveis e Decoração
                )

            [13] => stdClass Object
                (
                    [id] => MLB1051
                    [name] => Celulares e Telefones
                )

            [14] => stdClass Object
                (
                    [id] => MLB1798
                    [name] => Coleções e Comics
                )

            [15] => stdClass Object
                (
                    [id] => MLB5726
                    [name] => Eletrodomésticos
                )

            [16] => stdClass Object
                (
                    [id] => MLB1000
                    [name] => Eletrônicos, Áudio e Vídeo
                )

            [17] => stdClass Object
                (
                    [id] => MLB1276
                    [name] => Esportes e Fitness
                )

            [18] => stdClass Object
                (
                    [id] => MLB263532
                    [name] => Ferramentas e Construção
                )

            [19] => stdClass Object
                (
                    [id] => MLB3281
                    [name] => Filmes e Seriados
                )

            [20] => stdClass Object
                (
                    [id] => MLB1144
                    [name] => Games
                )

            [21] => stdClass Object
                (
                    [id] => MLB1459
                    [name] => Imóveis
                )

            [22] => stdClass Object
                (
                    [id] => MLB1648
                    [name] => Informática
                )

            [23] => stdClass Object
                (
                    [id] => MLB218519
                    [name] => Ingressos
                )

            [24] => stdClass Object
                (
                    [id] => MLB1182
                    [name] => Instrumentos Musicais
                )

            [25] => stdClass Object
                (
                    [id] => MLB3937
                    [name] => Joias e Relógios
                )

            [26] => stdClass Object
                (
                    [id] => MLB1196
                    [name] => Livros
                )

            [27] => stdClass Object
                (
                    [id] => MLB1168
                    [name] => Música
                )

            [28] => stdClass Object
                (
                    [id] => MLB264586
                    [name] => Saúde
                )

            [29] => stdClass Object
                (
                    [id] => MLB1540
                    [name] => Serviços
                )

            [30] => stdClass Object
                (
                    [id] => MLB1953
                    [name] => Mais Categorias
                )

        )

    [httpCode] => 200
)

 

cURL

[{"id":"MLB5672","name":"Acessórios para Veículos"},{"id":"MLB1499","name":"Agro, Indústria e Comércio"},{"id":"MLB1403","name":"Alimentos e Bebidas"},{"id":"MLB1071","name":"Animais"},{"id":"MLB1367","name":"Antiguidades"},{"id":"MLB1368","name":"Arte e Artesanato"},{"id":"MLB1384","name":"Bebês"},{"id":"MLB1246","name":"Beleza e Cuidado Pessoal"},{"id":"MLB1132","name":"Brinquedos e Hobbies"},{"id":"MLB1430","name":"Calçados, Roupas e Bolsas"},{"id":"MLB1039","name":"Câmeras e Acessórios"},{"id":"MLB1743","name":"Carros, Motos e Outros"},{"id":"MLB1574","name":"Casa, Móveis e Decoração"},{"id":"MLB1051","name":"Celulares e Telefones"},{"id":"MLB1798","name":"Coleções e Comics"},{"id":"MLB5726","name":"Eletrodomésticos"},{"id":"MLB1000","name":"Eletrônicos, Áudio e Vídeo"},{"id":"MLB1276","name":"Esportes e Fitness"},{"id":"MLB263532","name":"Ferramentas e Construção"},{"id":"MLB3281","name":"Filmes e Seriados"},{"id":"MLB1144","name":"Games"},{"id":"MLB1459","name":"Imóveis"},{"id":"MLB1648","name":"Informática"},{"id":"MLB218519","name":"Ingressos"},{"id":"MLB1182","name":"Instrumentos Musicais"},{"id":"MLB3937","name":"Joias e Relógios"},{"id":"MLB1196","name":"Livros"},{"id":"MLB1168","name":"Música"},{"id":"MLB264586","name":"Saúde"},{"id":"MLB1540","name":"Serviços"},{"id":"MLB1953","name":"Mais Categorias"}]

Share this post


Link to post
Share on other sites
  • 0

o problema está em algum lugar de seu código (basta jogar esse endpoint no próprio navegador que ele vai te retornar a árvore de categorias), como faz muito tempo que nem dou uma olhada em Delphi nem vou arriscar um palpite

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now