Painel | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
NewSintaxe
|
Painel | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
SetPathSintaxe
|
Painel | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
GetSintaxe
|
Painel |
---|
GetResultSintaxe |
Painel |
---|
GetLastErrorSintaxe |
Painel | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
PostSintaxe
|
Painel | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
SetPostParamsSintaxe
|
Painel | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PutSintaxe
|
...
|
Painel | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
DeleteSintaxe
|
...
|
Painel | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
SetChkStatusSintaxe Descrição
|
Painel | ||
---|---|---|
GetChkStatusSintaxe Descrição
|
Painel | ||
---|---|---|
GetHTTPCodeSintaxe Descrição
|
Painel | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
SetGetParamsSintaxe Descrição Parâmetros
|
Painel | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
SetLegacySuccessSintaxe Ex.:
|
Exemplo:
Bloco de código | ||||
---|---|---|---|---|
| ||||
user function tstFwRestTest()
local oRestClient as object
oRestClient := FWRest():New("http://code.google.com")
oRestClient:setPath("/p/json-path/")
if oRestClient:Get()
ConOut(oRestClient:GetResult())
else
ConOut(oRestClient:GetLastError())
endif
return |
Exemplo de envio de arquivo .gz:
Bloco de código | ||||
---|---|---|---|---|
| ||||
#include "protheus.ch"
//-------------------------------------------------------------------
/*/{Protheus.doc} x16165
Função para post na API /api/batch/contratos em
https://seusite.com.br, utilizando da classe
@sample U_x16165()
@author Daniel Mendes
@since 22/03/2019
@version 1.0
/*/
//-------------------------------------------------------------------
user function x16165()
local oRestClient as object
local cUrl as char
local cPath as char
local aHeadOut as array
local oFile as object
cUrl := "https://seusite.com.br"
cPath := "/api/batch/contratos"
aHeadOut := {}
Aadd(aHeadOut, "Authorization: Basic " + Encode64("app01:fTdUlDgdQQ4MRQhLahykiKhON6k97Zfly5SV6fwpa5zCE"))
Aadd(aHeadOut, "Content-Type: application/json")
Aadd(aHeadOut, "Content-Encoding: gzip")
oFile := FwFileReader():New("\contratos_20190316.gz")
if oFile:Open()
oRestClient := FWRest():New(cUrl)
oRestClient:SetPath(cPath)
oRestClient:SetPostParams(Encode64(oFile:FullRead()))
oFile:Close()
if oRestClient:Post(aHeadOut)
showResult(oRestClient:GetResult())
else
showResult(oRestClient:GetLastError())
endif
|
...
FreeObj( |
...
oRestClient) endif FreeObj(oFile) return //------------------------------------------------------------------- /*/{Protheus.doc} showResult Exibe o resultado do método POST, sendo em console ou tela @param cValue String contendo o conteúdo que será exibido @sample showResult("Teste") @author Daniel Mendes @since 22/03/2019 @version 1.0 /*/ //------------------------------------------------------------------- static function showResult(cValue) if IsBlind() Conout(cValue) else MsgInfo(cValue) endif return |