HttpGetResult - http://forum.pcsoft.fr/pt-BR
http://doc.windev.com/?3043001&lang=en-US&productversion=xxA190056s
http://forum.pcsoft.fr/pt-BR/pcsoft.br.windev/116-exemplos-uso-httprequest-httpgetresult/read.awp
----------------------------------------------------------------------------------------------------------------------
Examples
Ex01: Retorna Html
#####################################################
Code Button:
Url is string = "http://www.informaticon.com.br"
ok is boolean = HTTPRequest(Url)
IF ok = True
Info(ok )
retorno is string = HTTPGetResult()
ELSE
Info(ErrorInfo())
END
Ex02: Retorna Header DO Html
#####################################################
Code Button:
Url is string = "http://www.informaticon.com.br"
ok is boolean = HTTPRequest(Url)
IF ok = True
Info(ok )
retorno is string = HTTPGetResult(httpHeader)
ELSE
Info(ErrorInfo())
END
Ex03: Retorna Cookie
#####################################################
Code Button:
Url is string = "http://www.informaticon.com.br"
ok is boolean = HTTPRequest(Url)
IF ok = True
Info(ok )
retorno is string = HTTPGetResult(httpCookie)
ELSE
Info(ErrorInfo())
END
Ex04: Retorna html
#####################################################
Code Button:
Url is string = "http://www.informaticon.com.br"
ok is boolean = HTTPRequest(Url)
IF ok = True
Info(ok )
retorno is string = HTTPGetResult(httpResult)
ELSE
Info(ErrorInfo())
END
Ex05: Retorna uma imagem (download de arquivo)
#####################################################
Code Button:
ArquivoBaixado is Buffer
Url is string = "http://www.informaticon.com.br/j/images/stories/neri.jpg"
ok is boolean = HTTPRequest(Url)
IF ok = True
ArquivoBaixado = HTTPGetResult()
ELSE
Info(ErrorInfo())
END
fSaveBuffer("c:\fotodonerigaldeiro.jpg",ArquivoBaixado)
Ex06: Retorna uma executavel (download de arquivo)
#####################################################
Code Button:
ArquivoBaixado is Buffer
Url is string = "http://www.7-zip.org/a/7z920.exe"
ok is boolean = HTTPRequest(Url)
IF ok = True
ArquivoBaixado = HTTPGetResult()
ELSE
Info(ErrorInfo())
END
fSaveBuffer("7z920.exe",ArquivoBaixado)
Ex07: Envelope SOAP
#####################################################
Code Button:
PROCEDURE WS_Taxi_AtualizarCartoes(LOCAL DebugSN)
IF GloDebugSN = "S" THEN
Info("WS_Taxi_AtualizarCartoes")
DebugSN = "S"
END
ok is boolean = False
Contador is int = 0
bAtualizar is boolean = False
IpSaladaFruta01 is string = Morango_01 +"."+ Abacaxi_02 +"."+ Limao_03 +"."+ Melancia_04 +":"+ Laranja_05
IpSaladaFruta02 is string = Morango_01 +"."+ Abacaxi_02 +"."+ Limao_03 +"."+ Melancia_04 +":"+ Manga_06
ChangeCharset(charsetOccidental) // SEM ACENTO
//Busca Cliente
HReadSeekFirst(t001_cliente,t001_cliente.t001_seq_cliente,1)
IF HFound(t001_cliente) = True THEN
erro is int = 0
CodClienteCelula, nRetornoCodigo is int = 0
bRet is boolean = False
XML_Retorno, NumProces is string = ""
//Busca Cliente
HReadSeekFirst(t001_cliente,t001_cliente.t001_seq_cliente,1)
IF HFound(t001_cliente) = True THEN
//NumProcess
NumProces = WS_Taxi_ValidaRequisicao(t001_cliente.t001_ddd_telefone,...
t001_cliente.t001_num_telefone,...
0,...
0,...
"N")
//Envio
IF CodClienteCelula = "" OR CodClienteCelula = 0 THEN
CodClienteCelula = t001_cliente.t001_cod_clientecelula
END
//Envelope
Xml_SEND is string = [
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:act297_RtPlusSSDM-IRtPlusSSDM#AtualizarCartoes">
<soapenv:Header/>
<soapenv:Body>
<urn:AtualizarCartoes soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<cod_client_celula xsi:type="xsd:int">v001</cod_client_celula>
<dat_hora_proces xsi:type="xsd:string">v002</dat_hora_proces>
<num_proces xsi:type="xsd:int">v003</num_proces>
</urn:AtualizarCartoes>
</soapenv:Body>
</soapenv:Envelope>
]
//Replace
Xml_SEND = Replace(Xml_SEND,"v001",CodClienteCelula,IgnoreCase)
Xml_SEND = Replace(Xml_SEND,"v002",GloDataHora,IgnoreCase)
Xml_SEND = Replace(Xml_SEND,"v003",NumProces,IgnoreCase)
IF DebugSN = "S" THEN
Info("/mnt/sdcard/TaxiFv/Arquivos/EnvioCartoes.TXT", Xml_SEND)
IF InAndroidMode() = True
IF InSimulatorMode() = False
fSaveBuffer("/mnt/sdcard/TaxiFv/Arquivos/EnvioCartoes.TXT", Xml_SEND)
ELSE
fSaveBuffer("c:\EnvioCartoes.TXT", Xml_SEND)
END
END
END
HTTPTimeOut(GloHTTPTimeOut)
//BASE REAL
ok = HTTPRequest("http://"+IpSaladaFruta01+"/soap/IRtPlusSSDM","", "", Xml_SEND, "text/xml","","")
XML_Retorno = WS_Android_IOS_HTTPGetResult()
//Retorno Completo do webservice sem Tratamento
IF DebugSN = "S" THEN
Info("/mnt/sdcard/TaxiFv/Arquivos/RetornoCartoesSemTratamento.TXT", XML_Retorno)
IF InAndroidMode() = True
IF InSimulatorMode() = False
fSaveBuffer("/mnt/sdcard/TaxiFv/Arquivos/RetornoCartoesSemTratamento.TXT", XML_Retorno)
ELSE
fSaveBuffer("c:\RetornoCartoes.TXT", XML_Retorno)
END
END
END
//Retorno Completo do webservice com Tratamento
XML_Retorno = WS_RemoveAcentos(XML_Retorno)
//Ajuste do xml para ser lido
IF Length(XML_Retorno) > 0 THEN
Inicial is int = PositionOccurrence(XML_Retorno,"<NS2:TTipoFormaPagamentoVO",firstRank,FromBeginning)
Final is int = PositionOccurrence(XML_Retorno,"</NS2:TTipoFormaPagamentoVO>",lastRank,FromEnd) +Length("</NS2:TTipoFormaPagamentoVO>")
XML_Retorno = Middle(XML_Retorno,Inicial,Final - Inicial)
XML_Retorno = Replace(XML_Retorno,"NS2:TTipoFormaPagamentoVO","NoXml")
XML_Retorno = "<Xml><Recorte>"+XML_Retorno+"</Recorte></Xml>"
IF DebugSN = "S" THEN
Info("/mnt/sdcard/TaxiFv/Arquivos/RetornoCartoes.TXT", XML_Retorno)
IF InAndroidMode() = True
IF InSimulatorMode() = False
fSaveBuffer("/mnt/sdcard/TaxiFv/Arquivos/RetornoCartoes.TXT", XML_Retorno)
ELSE
fSaveBuffer("c:\RetornoCartoes.TXT", XML_Retorno)
END
END
END
IF Length(XML_Retorno) >0 THEN
HExecuteQuery(QRY_T004Cartoes_Del)
FOR EACH t004_cartoescreditos
HDelete(t004_cartoescreditos)
END
IF IniOSMode() = True THEN
/////////////////////////////////////////////////////////////
NoXml is string
i is int = 1
LOOP
NoXml = XMLExtractString(XML_Retorno,"NoXml",i)
IF NoXml = "" THEN
BREAK
END
DesFormaPagame is string = XMLExtractString(NoXml,"DesFormaPagame")
CodFormaPagame is string = XMLExtractString(NoXml,"CodFormaPagame")
IF DebugSN = "S"
Info("Cartao",CodFormaPagame,DesFormaPagame)
END
//Busca Cartao
HReadSeekFirst(t004_cartoescreditos,t004_cartoescreditos.NomeCartao004,DesFormaPagame)
IF HFound(t004_cartoescreditos) = False THEN
//Adicionando a leitura do xml no banco de dados
t004_cartoescreditos.CodigoCartao004 = CodFormaPagame
IF t004_cartoescreditos.CodigoCartao004 = 0 THEN
Contador += 1
t004_cartoescreditos.CodigoCartao004 = Contador
END
t004_cartoescreditos.NomeCartao004 = DesFormaPagame
t004_cartoescreditos.DataAtualizacao004 = DateSys()
IF DebugSN = "S" THEN
Info("tabela",t004_cartoescreditos.CodigoCartao004,t004_cartoescreditos.NomeCartao004)
END
//Arquiva resultado
ok = HAdd(t004_cartoescreditos)
IF ok = False THEN
//conta erros
erro += 1
ELSE
IF DebugSN = "S" THEN
Info("Adicionado com sucesso")
END
END
END
i++
END
ELSE IF InAndroidMode() = True
/////////////////////////////////////////////////////////////
XmlDoc is xmlDocument
XmlDoc = XMLOpen(XML_Retorno, fromString)
NoXml is xmlNode
//Leitura do xml em loop
FOR EACH NoXml OF XmlDoc.Xml.Recorte on NoXml
IF DebugSN = "S"
Info("Cartao",NoXml.CodFormaPagame,NoXml.DesFormaPagame)
END
//Busca Cartao
HReadSeekFirst(t004_cartoescreditos,t004_cartoescreditos.NomeCartao004,NoXml.DesFormaPagame)
IF HFound(t004_cartoescreditos) = False THEN
//Adicionando a leitura do xml no banco de dados
t004_cartoescreditos.CodigoCartao004 = NoXml.CodFormaPagame
IF t004_cartoescreditos.CodigoCartao004 = 0 THEN
Contador += 1
t004_cartoescreditos.CodigoCartao004 = Contador
END
t004_cartoescreditos.NomeCartao004 = NoXml.DesFormaPagame
t004_cartoescreditos.DataAtualizacao004 = DateSys()
IF DebugSN = "S" THEN
Info("tabela",t004_cartoescreditos.CodigoCartao004,t004_cartoescreditos.NomeCartao004)
END
//Arquiva resultado
ok = HAdd(t004_cartoescreditos)
IF ok = False THEN
//conta erros
erro += 1
ELSE
IF DebugSN = "S" THEN
Info("Adicionado com sucesso")
END
END
END
END
END
//Verifica quantos erros ocorreram se for maior que zero é falso o retorno
IF erro > 0 THEN
ok = False
ELSE
ok = True
END
//
END
END
END //
END
// //LEITURA E GRAVACAO
// //=========================================================
// FOR EACH t004_cartoescreditos
// IF t004_cartoescreditos.CodigoCartao004 > 0 THEN
// Contador += 1
// END
// END
// IF Contador = 0 THEN
//
// t004_cartoescreditos.CodigoCartao004 = 1
// t004_cartoescreditos.NomeCartao004 = "VISA"
// t004_cartoescreditos.DataAtualizacao004 = DateSys()
// HAdd(t004_cartoescreditos)
//
// t004_cartoescreditos.CodigoCartao004 = 2
// t004_cartoescreditos.NomeCartao004 = "MASTER"
// t004_cartoescreditos.DataAtualizacao004 = DateSys()
// HAdd(t004_cartoescreditos)
//
// t004_cartoescreditos.CodigoCartao004 = 4
// t004_cartoescreditos.NomeCartao004 = "HIPERCARD"
// t004_cartoescreditos.DataAtualizacao004 = DateSys()
// HAdd(t004_cartoescreditos)
//
// t004_cartoescreditos.CodigoCartao004 = 5
// t004_cartoescreditos.NomeCartao004 = "AMERICAN"
// t004_cartoescreditos.DataAtualizacao004 = DateSys()
// HAdd(t004_cartoescreditos)
//
// t004_cartoescreditos.CodigoCartao004 = 6
// t004_cartoescreditos.NomeCartao004 = "SENFF"
// t004_cartoescreditos.DataAtualizacao004 = DateSys()
// HAdd(t004_cartoescreditos)
//
// t004_cartoescreditos.CodigoCartao004 = 7
// t004_cartoescreditos.NomeCartao004 = "ELO"
// t004_cartoescreditos.DataAtualizacao004 = DateSys()
// HAdd(t004_cartoescreditos)
// END
RESULT(ok)
------------------------------------------------------------------------------------------------------