Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"Wish not to seem, but to be, the best." -- Aeschylus


devel / comp.lang.xharbour / Re: Download JSON to PDF

SubjectAuthor
* Download JSON to PDFAnderson Cardoso
`- Re: Download JSON to PDFAnderson Cardoso

1
Download JSON to PDF

<98f1cda3-2db8-47d6-8cb2-987fb7a5e6a5n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17077&group=comp.lang.xharbour#17077

  copy link   Newsgroups: comp.lang.xharbour
X-Received: by 2002:a05:6214:d4d:b0:499:2037:3be9 with SMTP id 13-20020a0562140d4d00b0049920373be9mr22207550qvr.121.1662390091723;
Mon, 05 Sep 2022 08:01:31 -0700 (PDT)
X-Received: by 2002:a0d:fa45:0:b0:345:6a28:d797 with SMTP id
k66-20020a0dfa45000000b003456a28d797mr1380744ywf.292.1662390091338; Mon, 05
Sep 2022 08:01:31 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.xharbour
Date: Mon, 5 Sep 2022 08:01:31 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=177.99.173.222; posting-account=vXb10QoAAACtql4X4XBjGCZA6sGzs_sw
NNTP-Posting-Host: 177.99.173.222
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <98f1cda3-2db8-47d6-8cb2-987fb7a5e6a5n@googlegroups.com>
Subject: Download JSON to PDF
From: acardososilva@gmail.com (Anderson Cardoso)
Injection-Date: Mon, 05 Sep 2022 15:01:31 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 52
 by: Anderson Cardoso - Mon, 5 Sep 2022 15:01 UTC

I am using a webservice that responses with a JSON file with a PDF inside: ["certidaoPDF"].

Response Class (Status 200):
application/json;charset=UTF-8
{ "razaoSocial":"string",
"nomeFantasia":string,
"cnpj":"string",
"uf":string,
"certidoes": [
{ "emissor":"TCU",
"tipo":"string",
"dataHoraEmissao":"13/04/2018 16:38",
"descricao":"string",
"situacao":"string",
"observacao":"string"
} ],
"certidaoPDF":"application/pdf"
}

I am using xHarbour v1.2.1 and there´s no hb_jsonDecode lib so I use was using this function below but it doesn´t work in this case:

Function JSontoHash( cStringJson )
/***
* Convert string Json format to Hash
*/
Local hJson := {=>}
cStringJson := StrTran( cStringJson,':[','=>{')
cStringJson := StrTran( cStringJson,'":"','" => "')
cStringJson := StrTran( cStringJson,'[','{')
cStringJson := StrTran( cStringJson,']','}')
cStringJson := StrTran( cStringJson,'":null','"=>nil')
cStringJson := StrTran( cStringJson,'":true' ,'"=>.t.' )
cStringJson := StrTran( cStringJson,'":false','"=>.f.')
cStringJson := StrTran( cStringJson,'":','"=>')
cStringJson := StrTran( cStringJson,"\/","/" )
hJSon := &( cStringJson )
Return hJson

This is my code:

http := CreateObject("MSXML2.ServerXMLHTTP")
http:Open("GET", "https://certidoes-apf.apps.tcu.gov.br/api/rest/publico/certidoes/"+cCNPJ+"?seEmitirPDF=true", .F.)
http:send()
JSONCNPJ := http:responseText
hCNPJ := JSontoHash(JSONCNPJ) // RETURNS AN ERROR HERE

My objective is to download that PDF.

Re: Download JSON to PDF

<c7582f7f-d852-4c11-8944-475f41675eb7n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17082&group=comp.lang.xharbour#17082

  copy link   Newsgroups: comp.lang.xharbour
X-Received: by 2002:a05:6214:daf:b0:49f:5ce8:e628 with SMTP id h15-20020a0562140daf00b0049f5ce8e628mr14605390qvh.115.1662781111895;
Fri, 09 Sep 2022 20:38:31 -0700 (PDT)
X-Received: by 2002:a25:4884:0:b0:6ae:b301:daf3 with SMTP id
v126-20020a254884000000b006aeb301daf3mr866916yba.372.1662781111581; Fri, 09
Sep 2022 20:38:31 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.xharbour
Date: Fri, 9 Sep 2022 20:38:31 -0700 (PDT)
In-Reply-To: <98f1cda3-2db8-47d6-8cb2-987fb7a5e6a5n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=206.42.32.40; posting-account=vXb10QoAAACtql4X4XBjGCZA6sGzs_sw
NNTP-Posting-Host: 206.42.32.40
References: <98f1cda3-2db8-47d6-8cb2-987fb7a5e6a5n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c7582f7f-d852-4c11-8944-475f41675eb7n@googlegroups.com>
Subject: Re: Download JSON to PDF
From: acardososilva@gmail.com (Anderson Cardoso)
Injection-Date: Sat, 10 Sep 2022 03:38:31 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3348
 by: Anderson Cardoso - Sat, 10 Sep 2022 03:38 UTC

Em segunda-feira, 5 de setembro de 2022 às 12:01:32 UTC-3, Anderson Cardoso escreveu:
> I am using a webservice that responses with a JSON file with a PDF inside: ["certidaoPDF"].
>
> Response Class (Status 200):
> application/json;charset=UTF-8
> {
> "razaoSocial":"string",
> "nomeFantasia":string,
> "cnpj":"string",
> "uf":string,
> "certidoes": [
> {
> "emissor":"TCU",
> "tipo":"string",
> "dataHoraEmissao":"13/04/2018 16:38",
> "descricao":"string",
> "situacao":"string",
> "observacao":"string"
> }
> ],
> "certidaoPDF":"application/pdf"
> }
>
> I am using xHarbour v1.2.1 and there´s no hb_jsonDecode lib so I use was using this function below but it doesn´t work in this case:
>
> Function JSontoHash( cStringJson )
> /***
> * Convert string Json format to Hash
> */
> Local hJson := {=>}
> cStringJson := StrTran( cStringJson,':[','=>{')
> cStringJson := StrTran( cStringJson,'":"','" => "')
> cStringJson := StrTran( cStringJson,'[','{')
> cStringJson := StrTran( cStringJson,']','}')
> cStringJson := StrTran( cStringJson,'":null','"=>nil')
> cStringJson := StrTran( cStringJson,'":true' ,'"=>.t.' )
> cStringJson := StrTran( cStringJson,'":false','"=>.f.')
> cStringJson := StrTran( cStringJson,'":','"=>')
> cStringJson := StrTran( cStringJson,"\/","/" )
> hJSon := &( cStringJson )
> Return hJson
>
> This is my code:
>
> http := CreateObject("MSXML2.ServerXMLHTTP")
> http:Open("GET", "https://certidoes-apf.apps.tcu.gov.br/api/rest/publico/certidoes/"+cCNPJ+"?seEmitirPDF=true", .F.)
> http:send()
> JSONCNPJ := http:responseText
> hCNPJ := JSontoHash(JSONCNPJ) // RETURNS AN ERROR HERE
>
> My objective is to download that PDF.

Problem solved with hb_jsonDecode() and HB_Base64Decode():

hb_jsonDecode( JSONCNPJ, @hCNPJ )
// SALVA PDF
nFileHandle := FCreate(fCERTIDAO)
FWRITE(nFileHandle, HB_Base64Decode( hCNPJ["certidaoPDF"]) )
FCLOSE(nFileHandle)

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor