Verifique se a chave SECURITY da seção Socket esta configurado com valor 1 para testar o código abaixo

Os métodos Put e Delete da classe FWRest estarão disponíveis na Lib label 28012015

#include "totvs.ch"

User Function restSample()
Local oRestClient := FWRest():New("http://localhost:8080")
Local aHeader := {"tenantId: 99,01"}

// inclui o campo Authorization no formato <usuario>:<senha> na base64
Aadd(aHeader, "Authorization: Basic " + Encode64("admin:123456"))

// chamada da classe exemplo de REST com retorno de lista 
oRestClient:setPath("/rest/sample?startIndex=2&count=10")
If oRestClient:Get(aHeader)
   ConOut("GET", oRestClient:GetResult())
Else
   ConOut("GET", oRestClient:GetLastError())
EndIf
 
// chamada da classe exemplo de REST para operações CRUD
oRestClient:setPath("/rest/sample/1")
If oRestClient:Get(aHeader)
   ConOut("GET", oRestClient:GetResult())
Else
   ConOut("GET", oRestClient:GetLastError())
EndIf

 
// define o conteúdo do body
oRestClient:SetPostParams("body")
 
If oRestClient:Post(aHeader)
   ConOut("POST", oRestClient:GetResult())
Else
   ConOut("POST", oRestClient:GetLastError())
EndIf

 
// para os métodos PUT e DELETE o conteúdo body é enviado por parametro
If oRestClient:Put(aHeader, "body")
   ConOut("PUT", oRestClient:GetResult())
Else
   ConOut("PUT", oRestClient:GetLastError())
EndIf

If oRestClient:Delete(aHeader, "body")
   ConOut("DELETE", oRestClient:GetResult())
Else
   ConOut("DELETE", oRestClient:GetLastError())
EndIf
Return 

 Veja também

 

Encode64

Criando uma classe REST

 

 

 

  • Sem rótulos