Classe para trabalhar com Webservice do tipo Rest Full API - EXEMPLOS RESTSEND |
|
|
Classe para trabalhar com Webservice do tipo Rest Full API
Class to work with Webservice of type Restful API
EXEMPLOS RESTSEND
Ajuda para desenvolver o projeto foi graças ao Willian Padilha
ADRIANO BOLLER REPRESENTANTE PC SOFT NO BRASIL adrianoboller@gmail.com http://www.wxinformatica.com.br +55 (41) 99949 1800 skype adrianoboller |
| |
| |
| Illustrations, copies d'écran |
|
| |
(Pour noter la ressource, cliquez sur Ecrire un avis) |
| |
pour pouvoir poster un avis |
| | |
| | |
Aucun avis ou commentaire ? Soyez le premier ! |
PROCEDURE HttpExecutarRestApi(s_url is string, s_parametros is string, b_via_post is boolean, arr_header_parametros is array of ST_parametros_header, b_codificar_parametros is boolean = True, s_content_type is string = "" ) //Http Rest WHEN EXCEPTION IN //info(1) tempo_ocioso is int = 0 gbResultOK is boolean sResultado, sUltimo_erro is string ChangeCharset(charsetOccidental) // SEM ACENTO
HourGlass(True) cMyRequest is a httpRequest cMyResponse is a httpResponse cMyRequest..URL = s_url //cMyRequest..TimeOutConnexion = 30000 //info(2) IF Length(s_parametros) > 0 THEN IF b_codificar_parametros OR PositionOccurrence(s_parametros,"{",firstRank,WholeWord) = 0 cMyRequest..Content = URLEncode(s_parametros) ELSE cMyRequest..Content = s_parametros END END IF s_content_type <> "" THEN cMyRequest..ContentType = s_content_type END IF b_via_post = True THEN cMyRequest..Method = httpPost //2 ELSE cMyRequest..Method = httpGet //1 END IF ArrayCount(arr_header_parametros) > 0 THEN FOR EACH st_parametro OF arr_header_parametros cMyRequest.Header[st_parametro.s_nome_parametro] = st_parametro.s_valor_parametro END END //info(3) //Executa a requisição gbResultOK = False
cMyResponse = RESTSend ( cMyRequest ) //info(4) Trace("--------------------------------------") Trace("URL "+cMyRequest..URL) Trace("Envio: " + cMyRequest..Method +CR+ cMyRequest..Content +CR+ cMyRequest..ContentType) Trace("Retorno: " +cMyResponse..Content) Trace("--------------------------------------") IF ErrorOccurred OR PositionOccurrence(cMyResponse..Content,"DOCTYPE html PUBLIC",firstRank,FromBeginning) > 0 gbResultOK = False sUltimo_erro = s_url+s_parametros +" "+ ErrorInfo(errFullDetails) HourGlass(False) Add(garry_Resultado,False) RESULT False ELSE gbResultOK = True sResultado = NoAccent(cMyResponse..Content) Add(garry_Resultado,cMyResponse..Header) Add(garry_Resultado,cMyResponse..Content) Add(garry_Resultado,cMyResponse..ContentType) Add(garry_Resultado,cMyResponse..DescriptionStatusCode) Add(garry_Resultado,cMyResponse..RoughHeader) Add(garry_Resultado,cMyResponse..StatusCode) Add(garry_Resultado,True) HourGlass(False) RESULT sResultado END DO
gbResultOK = False Add(garry_Resultado,False) HourGlass(False)
RESULT False
END
///----------- global init
GLOBAL gsUser is string garry_Resultado is array of string //esta Structure é usado para passar parametros ao HEADER do request ST_parametros_header est Structure s_nome_parametro est chaîne s_valor_parametro est chaîne FIN |
| | |
|
WINDEV, WEBDEV, WINDEV Mobile |
| | | | | |