Consegui fazer funcionar, estava errando no campo logradouro, não consegui entender como funciona esta pesquisa preenchendo este campo logradouro.
Mesmo pelo exemplo do Daniel, preenchendo este campo, não consigo retorno.
Desse jeito, bem meia boca, ta funcionando com HB34+MINGW + HWGUI 2.20, e so colocar o CEP ou endereco+cidade que lista tudo o que há...
/*
COMPILAR:
HBMK2 C:\HWGUI\HWGUI.HBC C:\HB34\CONTRIB\HBTIP\HBTIP.HBC HBWIN.HBC CEP.PRG
Baseado no exemplo de:
//=========================================================================
//
// Arquivo.....: Cep.prg
// Criado em...: 02-01-2017 as 07:56 PM
//
// Projeto.....: Consulta Simples
//
// Programador.: Daniel Denobie - denobie@hotmail.com
//
//=========================================================================
*/
#include "hwgui.ch"
#include "directry.ch"
#include "Fileio.ch"
#include "tip.ch"
MemVar cUrl, cUrl1, cQuery, oServer, cCookie, cRet, cFile, cRet1, cRet2, nIni, nFim
Memvar cArq, cArq1, cArq2, cArq3
Function Main()
private cCep:=SPAC(50), cLogradouro:=[], cUf:=[], xCEP:=SPAC(50)
private MATA:={}
XCEP := MsgGet_Correio([Pesquisar por rua],[cep ou rua ], xCEP)
Consulta_Cep(xCEP, cLogradouro, cUF)
if len(mata) > 0
TELA()
endif
Return Nil
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *>
Function MsgGet_Correio( cTitle, cText, xCEP)
Local oModDlg, oFont := HFont():Add( "MS Sans Serif",0,-13 )
LOCAL oGET101
INIT DIALOG oModDlg TITLE cTitle SIZE 300,140 ;
FONT oFont CLIPPER STYLE DS_MODALFRAME + WS_POPUP + WS_VISIBLE + WS_CAPTION + WS_SYSMENU + DS_CENTER
@ 20,10 SAY cText SIZE 260,22
@ 20,35 GET oGET101 VAR xCEP SIZE 150,24 PICTURE "@X" STYLE WS_TABSTOP
@ 200,95 BUTTON "Ok" ID IDOK SIZE 80,24
ACTIVATE DIALOG oModDlg
oFont:Release()
Return xCEP
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Function Consulta_Cep(cCep, cLogradouro, cUf) // consulta do cep esta funcionando ate bem
If !Empty(AllTrim(cLogradouro))
cUrl := 'http://www.buscacep.correios.com.br/sistemas/buscacep/BuscaCep.cfm'
cUrl1 := 'http://www.buscacep.correios.com.br/sistemas/buscacep/resultadoBuscaCep.cfm'
cQuery:= 'UF=' + cUf +;
'&Localidade=' + cCep +;
'&Tipo=' +;
'&Logradouro=' + AllTrim(cLogradouro) +;
'&Numero='
Else
cUrl := "http://www.buscacep.correios.com.br/sistemas/buscacep/BuscaCepEndereco.cfm"
cUrl1 := 'http://www.buscacep.correios.com.br/sistemas/buscacep/resultadoBuscaCepEndereco.cfm'
cQuery:= "relaxation=" + AllTrim(cCep) +;
"&tipoCEP=ALL" +;
"&semelhante=N"
EndIf
BEGIN SEQUENCE WITH __BreakBlock()
oServer:= win_OleCreateObject( "MSXML2.ServerXMLHTTP.5.0")
End
BEGIN SEQUENCE WITH __BreakBlock()
oServer:Open( "GET", cUrl, .f. )
oServer:SetRequestHeader( "Content-Type", "application/x-www-form-urlencoded" )
oServer:SetRequestHeader( "Connection", "keep-alive" )
oServer:Send()
oServer:WaitForResponse( 5000 )
End
cCookie:= oServer:getResponseHeader("Set-Cookie")
cRet := oServer:ResponseBody
//MemoWrit("site.txt", cRet)
BEGIN SEQUENCE WITH __BreakBlock()
oServer:= win_OleCreateObject( "MSXML2.ServerXMLHTTP.5.0")
End
BEGIN SEQUENCE WITH __BreakBlock()
oServer:Open( "POST", cUrl1, .f. )
oServer:SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
oServer:SetRequestHeader("Connection", "keep-alive" )
oServer:SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
oServer:SetRequestHeader("Accept-Language", "pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3")
oServer:SetRequestHeader("Upgrade-Insecure-Requests", '1')
oServer:SetRequestHeader("Cookie", cCookie)
oServer:Send(cQuery)
oServer:WaitForResponse( 5000 )
end
cFile:= oServer:ResponseBody
cRet1:= StrTran(cFile,Chr(13)+Chr(10),"")
cRet2:= StrTran(cRet1,Chr(160),"")
cRet := StrTran(cRet1,Chr(13),"")
//MemoWrit("Result.txt", cRet)
nIni := At('function detalhaCep(CEP)', cRet)
If nIni == 0
hwg_MsgInfo('Sem arquivo de CEP ', 'Aviso') // para aqui?????
Return Nil
EndIf
nIni := At('document.Geral.submit();}</script><p>', cRet)
If nIni == 0
Return nil
EndIf
nIni+= 37
cRet1:= SubStr(cRet, nIni)
nFim := At('</p>', cRet1) - 1
hwg_msgInfo(Troca_Acento(SubStr(cRet, nIni, nFim)), [teste aqui])
While .t.
nIni := At('<td width="150">', cRet)
if nIni == 0
exit
EndIf
nIni+= 16
cRet1:= SubStr(cRet, nIni)
If At('<a href="javascript:detalhaCep', cRet1) == 1
nIni += 45
cRet1 := SubStr(cRet, nIni)
nFim := At(' </a>', cRet1) - 1
cArq := Troca_Acento(StrTran(SubStr(cRet, nIni, nFim), '<br><br>', '-')) //Endereço
Else
nFim := At(' </td>', cRet1) - 1
cArq := Troca_Acento(SubStr(cRet, nIni, nFim)) //Endereço
EndIf
nIni := At(' </td><td width="90">', cRet)
If nIni == 0
nIni:= At(' </a></td><td width="90"', cRet)
nIni+= 30
Else
nIni+= 26
EndIf
cRet1:= SubStr(cRet, nIni)
nFim := At(' </td>', cRet1) - 1
cArq1:= Troca_Acento(SubStr(cRet, nIni, nFim)) //Bairro
nIni := At(' </td><td width="80">', cRet)
nIni += 26
cRet1:= SubStr(cRet, nIni)
nFim := At('</td><td width="55">', cRet1) - 1
cArq2:= Troca_Acento(SubStr(cRet, nIni, nFim)) //Cidade/Uf
nIni := (At('</td><td width="55">', cRet) + 20)
cRet1:= SubStr(cRet, nIni)
nFim := At('</td></tr>', cRet1) - 1
cArq3:= SubStr(cRet, nIni, nFim) //CEP
cRet := cRet1
IF !EMPTY(cArq3)
AADD ( MATA, {cArq3, cArq, cArq1, cArq2} )
ENDIF
End
Return Nil
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Function Troca_Acento(cTexto)
cTexto := StrTran( cTexto, "ç", "ç" )
cTexto := StrTran( cTexto, "Ç", "Ç" )
cTexto := StrTran( cTexto, "ã", "ã" )
cTexto := StrTran( cTexto, "Ã", "Ã" )
cTexto := StrTran( cTexto, "õ", "õ" )
cTexto := StrTran( cTexto, "Õ", "Õ" )
cTexto := StrTran( cTexto, "â" , "â" )
cTexto := StrTran( cTexto, "Â" , "Â" )
cTexto := StrTran( cTexto, "ê" , "ê" )
cTexto := StrTran( cTexto, "Ê" , "Ê" )
cTexto := StrTran( cTexto, "á", "á" )
cTexto := StrTran( cTexto, "Á", "Á" )
cTexto := StrTran( cTexto, "é", "é" )
cTexto := StrTran( cTexto, "É", "É" )
cTexto := StrTran( cTexto, "í", "í" )
cTexto := StrTran( cTexto, "Í", "Í" )
cTexto := StrTran( cTexto, "ó", "ó" )
cTexto := StrTran( cTexto, "Ó", "Ó" )
cTexto := StrTran( cTexto, "ú", "ú" )
cTexto := StrTran( cTexto, "Ú", "Ú" )
cTexto := StrTran( cTexto, "à", "à" )
cTexto := StrTran( cTexto, "À", "À" )
cTexto := StrTran( cTexto, "è", "è" )
cTexto := StrTran( cTexto, "È", "È" )
cTexto := StrTran( cTexto, "ì", "ì" )
cTexto := StrTran( cTexto, "Ì", "Ì" )
cTexto := StrTran( cTexto, "ò", "ò" )
cTexto := StrTran( cTexto, "Ò", "Ò" )
cTexto := StrTran( cTexto, "ù", "ù" )
cTexto := StrTran( cTexto, "Ù", "Ù" )
cTexto := StrTran( cTexto, "ï" , "ï" )
cTexto := StrTran( cTexto, "Ï" , "Ï" )
cTexto := StrTran( cTexto, "ü" , "ü" )
cTexto := StrTran( cTexto, "Ü" , "Ü" )
Return cTexto
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
FUNCTION TELA()
LOCAL oDlg_Dados_NFe, oBrw_NFE, oButton1
INIT DIALOG oDlg_Dados_NFe TITLE "Dados" AT 0, 0 SIZE 993,606 ;
FONT HFont():Add( 'Verdana',0,-14,400,,,) CLIPPER NOEXITESC ;
STYLE WS_POPUP+WS_CAPTION+WS_SYSMENU+WS_SIZEBOX+WS_MINIMIZEBOX+WS_MAXIMIZEBOX+DS_CENTER
This_Hwg_Dados_NFe := oDlg_Dados_NFe
@ 15,45 BROWSE oBrw_NFE ARRAY SIZE 935,450 STYLE WS_TABSTOP+WS_HSCROLL
hwg_CREATEARLIST( oBrw_NFE, Mata )
oBrw_NFE:aColumns[01]:heading := "CEP "
oBrw_NFE:aColumns[02]:heading := "Endereco "
oBrw_NFE:aColumns[03]:heading := "Bairro "
oBrw_NFE:aColumns[04]:heading := "Cidade "
oBrw_NFE:aColumns[01]:nJusHead := DT_CENTER
oBrw_NFE:aColumns[02]:nJusHead := DT_LEFT
oBrw_NFE:aColumns[03]:nJusHead := DT_LEFT
oBrw_NFE:aColumns[04]:nJusHead := DT_LEFT
oBrw_NFE:Refresh()
oBrw_NFE:Setfocus()
@ 841,556 BUTTON oButton1 CAPTION "Sai&r" SIZE 135,35 STYLE BS_CENTER +WS_TABSTOP ;
ON CLICK {|| This_Hwg_Dados_NFe:Close() }
ACTIVATE DIALOG oDlg_Dados_NFe
RETURN NIL