infosys2 Posted July 24, 2021 Report Share Posted July 24, 2021 Boa Tarde Gostaria de saber se alguém consegue me ajudar a fazer uma função para consumir o web service da prefeitura de Atibaia. Encontre alguns exemplos na documentação do web service de atibia em outras linguagens. LibCurl CURL *hnd = curl_easy_init(); curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST"); curl_easy_setopt(hnd, CURLOPT_URL, "http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula"); struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "postman-token: 26e44762-e741-d9bc-d1e4-200f018ad85f"); headers = curl_slist_append(headers, "cache-control: no-cache"); headers = curl_slist_append(headers, "content-type: application/xml"); headers = curl_slist_append(headers, "authorization: 999991-2EU2TPWLJBP2H57HL605K24778989PPP"); curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, " XML A SER ENVIADO"); CURLcode ret = curl_easy_perform(hnd); cURL curl -X POST \ http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula \ -H 'authorization: 999991-2EU2TPWLJBP2H57HL605K24778989PPP' \ -H 'cache-control: no-cache' \ -H 'content-type: application/xml' \ -H 'postman-token: 25a25272-851b-1763-f96f-6ac0017ad209' \ -d ' XML A SER ENVIADO' C# Sharp var client = new RestClient("http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula"); var request = new RestRequest(Method.POST); request.AddHeader("postman-token", "f6645f63-84a0-36b8-0e37-b26a359830ae"); request.AddHeader("cache-control", "no-cache"); request.AddHeader("content-type", "application/xml"); request.AddHeader("authorization", "999991-2EU2TPWLJBP2H57HL605K24778989PPP"); request.AddParameter("application/xml", " XML A SER Quote Link to comment Share on other sites More sharing options...
infosys2 Posted July 25, 2021 Author Report Share Posted July 25, 2021 17 horas atrás, infosys2 disse: Boa Tarde Gostaria de saber se alguém consegue me ajudar a fazer uma função para consumir o web service da prefeitura de Atibaia. Encontre alguns exemplos na documentação do web service de atibia em outras linguagens. LibCurl CURL *hnd = curl_easy_init(); curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST"); curl_easy_setopt(hnd, CURLOPT_URL, "http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula"); struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "postman-token: 26e44762-e741-d9bc-d1e4-200f018ad85f"); headers = curl_slist_append(headers, "cache-control: no-cache"); headers = curl_slist_append(headers, "content-type: application/xml"); headers = curl_slist_append(headers, "authorization: 999991-2EU2TPWLJBP2H57HL605K24778989PPP"); curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, " XML A SER ENVIADO"); CURLcode ret = curl_easy_perform(hnd); cURL curl -X POST \ http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula \ -H 'authorization: 999991-2EU2TPWLJBP2H57HL605K24778989PPP' \ -H 'cache-control: no-cache' \ -H 'content-type: application/xml' \ -H 'postman-token: 25a25272-851b-1763-f96f-6ac0017ad209' \ -d ' XML A SER ENVIADO' C# Sharp var client = new RestClient("http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula"); var request = new RestRequest(Method.POST); request.AddHeader("postman-token", "f6645f63-84a0-36b8-0e37-b26a359830ae"); request.AddHeader("cache-control", "no-cache"); request.AddHeader("content-type", "application/xml"); request.AddHeader("authorization", "999991-2EU2TPWLJBP2H57HL605K24778989PPP"); request.AddParameter("application/xml", " XML A SER Eu tentei fazer desta forma mas não deu certo! #Include "Fivewin.ch" //-------------------------------- Function Main() local cUrl:= "http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula" Try oHttp := CreateObject( 'MSXML2.XMLHTTP' ) Catch oHttp := CreateObject( 'Microsoft.XMLHTTP' ) End oHttp:Open( 'POST' , cUrl , .F. ) *oDoc:LoadXML( cXml ) //carga el documento a xml ohttp:SetRequestHeader( "Authorization" , "999991-2EU2TPWLJBP2H57HL605K24778989PPP" ) ohttp:SetRequestHeader( "postman-token" , "06646388:AAEr-QL8dNx2k6w7u0nEAOWld2Po" ) // envio xml oHttp:send("<consulta><inscricaoMunicipal>999991</inscricaoMunicipal><codigoVerificacao>2978937BMA</codigoVerificacao></consulta>") cRespuesta:= oHttp:responseText ? cRespuesta return nil Exemplos contido na documentação WEB SERVICE – EXEMPLOS DE EXECUÇÃO DO WEBSERVICE EM DIVERSAS LINGUAGEM DE PROGRAMAÇÃO LINGUAGEM C LibCurl CURL *hnd = curl_easy_init(); curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST"); curl_easy_setopt(hnd, CURLOPT_URL, "http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula"); struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "postman-token: 26e44762-e741-d9bc-d1e4-200f018ad85f"); headers = curl_slist_append(headers, "cache-control: no-cache"); headers = curl_slist_append(headers, "content-type: application/xml"); headers = curl_slist_append(headers, "authorization: 999991-2EU2TPWLJBP2H57HL605K24778989PPP"); curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, " XML A SER ENVIADO"); CURLcode ret = curl_easy_perform(hnd); cURL curl -X POST \ http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula \ -H 'authorization: 999991-2EU2TPWLJBP2H57HL605K24778989PPP' \ -H 'cache-control: no-cache' \ -H 'content-type: application/xml' \ -H 'postman-token: 25a25272-851b-1763-f96f-6ac0017ad209' \ -d ' XML A SER ENVIADO' C# Sharp var client = new RestClient("http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula"); var request = new RestRequest(Method.POST); request.AddHeader("postman-token", "f6645f63-84a0-36b8-0e37-b26a359830ae"); request.AddHeader("cache-control", "no-cache"); request.AddHeader("content-type", "application/xml"); request.AddHeader("authorization", "999991-2EU2TPWLJBP2H57HL605K24778989PPP"); request.AddParameter("application/xml", " XML A SER ENVIADO", ParameterType.RequestBody); IRestResponse response = client.Execute(request); LINGUAGEM JAVA OK HTTP OkHttpClient client = new OkHttpClient(); MediaType mediaType = MediaType.parse("application/xml"); RequestBody body = RequestBody.create(mediaType, " XML A SER ENVIADO"); Request request = new Request.Builder() .url("http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula") .post(body) .addHeader("authorization", "999991-2EU2TPWLJBP2H57HL605K24778989PPP") .addHeader("content-type", "application/xml") .addHeader("cache-control", "no-cache") .addHeader("postman-token", "dc16978a-e237-b880-24e4-3ca35eab00b3") .build(); Response response = client.newCall(request).execute(); Unirest HttpResponse<String> response = Unirest.post("http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula") .header("authorization", "999991-2EU2TPWLJBP2H57HL605K24778989PPP") .header("content-type", "application/xml") .header("cache-control", "no-cache") .header("postman-token", "67b88492-17dd-7d35-e267-17f0aeccf5b8") .body(" XML A SER ENVIADO") .asString(); LINGUAGEM – JAVASCRIPT JQUERY var settings = { "async": true, "crossDomain": true, "url": "http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula", "method": "POST", "headers": { "authorization": "999991-2EU2TPWLJBP2H57HL605K24778989PPP", "content-type": "application/xml", "cache-control": "no-cache", "postman-token": "aa7b25cd-9870-4605-7e15-a25ce549cbbc" }, "data": " XML A SER ENVIADO" } $.ajax(settings).done(function (response) { console.log(response); }); XHR var data = " XML A SER ENVIADO"; var xhr = new XMLHttpRequest(); xhr.withCredentials = true; xhr.addEventListener("readystatechange", function () { if (this.readyState === 4) { console.log(this.responseText); } }); xhr.open("POST", "http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula"); xhr.setRequestHeader("authorization", "999991-2EU2TPWLJBP2H57HL605K24778989PPP"); xhr.setRequestHeader("content-type", "application/xml"); xhr.setRequestHeader("cache-control", "no-cache"); xhr.setRequestHeader("postman-token", "044267bc-306d-0093-f98f-e4124b4dbc44"); xhr.send(data); LINGUAGEM – NODEJS NATIVE var http = require("http"); var options = { "method": "POST", "hostname": "webservice.giap.com.br", "port": null, "path": "/WSNfses/nfseresources/ws/v2/emissao/simula", "headers": { "authorization": "999991-2EU2TPWLJBP2H57HL605K24778989PPP", "content-type": "application/xml", "cache-control": "no-cache", "postman-token": "6f3c611b-ef46-e723-82be-0bf804f35636" } }; var req = http.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function () { var body = Buffer.concat(chunks); console.log(body.toString()); }); }); req.write(" XML A SER ENVIADO"); req.end(); REQUEST var request = require("request"); var options = { method: 'POST', url: 'http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula', headers: { 'postman-token': '16baa6d5-7845-8a94-f6e6-881e6a98924a', 'cache-control': 'no-cache', 'content-type': 'application/xml', authorization: '999991-2EU2TPWLJBP2H57HL605K24778989PPP' }, body: ' XML A SER ENVIADO' }; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); }); UNIREST var unirest = require("unirest"); var req = unirest("POST", "http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula"); req.headers({ "postman-token": "07503d21-1a63-405e-d24e-84332f21cdd1", "cache-control": "no-cache", "content-type": "application/xml", "authorization": "999991-2EU2TPWLJBP2H57HL605K24778989PPP" }); req.send(" XML A SER ENVIADO"); req.end(function (res) { if (res.error) throw new Error(res.error); console.log(res.body); }); LINGUAGEM – PHP HttpRequest <?php $request = new HttpRequest(); $request->setUrl('http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula'); $request->setMethod(HTTP_METH_POST); $request->setHeaders(array( 'postman-token' => 'bde5f2ea-327a-ee59-1178-2a7b68a738e1', 'cache-control' => 'no-cache', 'content-type' => 'application/xml', 'authorization' => '999991-2EU2TPWLJBP2H57HL605K24778989PPP' )); $request->setBody(' XML A SER ENVIADO'); try { $response = $request->send(); echo $response->getBody(); } catch (HttpException $ex) { echo $ex; } pecl_http <?php $client = new http\Client; $request = new http\Client\Request; $body = new http\Message\Body; $body->append(' XML A SER ENVIADO'); $request->setRequestUrl('http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula'); $request->setRequestMethod('POST'); $request->setBody($body); $request->setHeaders(array( 'postman-token' => '559a1ef4-fcd3-fc4c-537b-9ed6c96fda4b', 'cache-control' => 'no-cache', 'content-type' => 'application/xml', 'authorization' => '999991-2EU2TPWLJBP2H57HL605K24778989PPP' )); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); cURL <?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => " XML A SER ENVIADO", CURLOPT_HTTPHEADER => array( "authorization: 999991-2EU2TPWLJBP2H57HL605K24778989PPP", "cache-control: no-cache", "content-type: application/xml", "postman-token: 93d65476-41c5-90c3-05ae-6103573b41ba" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } LINGUAGEM – PYTHON http.client (PYTHON 3) import http.client conn = http.client.HTTPConnection("webservice.giap.com.br") payload = " XML A SER ENVIADO" headers = { 'authorization': "999991-2EU2TPWLJBP2H57HL605K24778989PPP", 'content-type': "application/xml", 'cache-control': "no-cache", 'postman-token': "f7bcfadb-78ad-925c-51f0-cafb384c3dab" } conn.request("POST", "/WSNfses/nfseresources/ws/v2/emissao/simula", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8")) requests import requests url = "http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula" payload = " XML A SER ENVIADO" headers = { 'authorization': "999991-2EU2TPWLJBP2H57HL605K24778989PPP", 'content-type': "application/xml", 'cache-control': "no-cache", 'postman-token': "f8281546-13aa-9e25-a5fe-32b81207ac21" } response = requests.request("POST", url, data=payload, headers=headers) print(response.text) LINGUAGEM – RUBY RUBY require 'uri' require 'net/http' url = URI("http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula") http = Net::HTTP.new(url.host, url.port) request = Net::HTTP::Post.new(url) request["authorization"] = '999991-2EU2TPWLJBP2H57HL605K24778989PPP' request["content-type"] = 'application/xml' request["cache-control"] = 'no-cache' request["postman-token"] = 'c4f9c73a-a7ad-efe3-00a3-2d5aa19db3f8' request.body = " XML A SER ENVIADO" response = http.request(request) puts response.read_body Quote Link to comment Share on other sites More sharing options...
Wellington Vieira Posted July 25, 2021 Report Share Posted July 25, 2021 Boa tarde, Eu uso o (UNINFE), tem muitas inúmeras cidades já contempladas no projeto http://www.unimake.com.br/uninfe/ e uso também o projeto Jose Quintas ( sefazclass ) https://github.com/JoseQuintas/sefazclass Dê uma olhada, talvez lhe ajude, principalmente no projeto do JOSE QUINTAS, já que você quer desenvolver. (são fontes). Quote Link to comment Share on other sites More sharing options...
infosys2 Posted July 25, 2021 Author Report Share Posted July 25, 2021 Unimake nao tem a cidade de atibaia Quote Link to comment Share on other sites More sharing options...
Wellington Vieira Posted July 25, 2021 Report Share Posted July 25, 2021 Basta SOLICITAR NO GRUPO https://groups.google.com/g/uninfe , aos ADMINISTRADORES a inclusão da cidade de "ATIBAIA", que a UNIMAKE insere a cidade para você. Funcionou assim para todas as cidades que hoje lá tem, eu mesmo solicitei algumas. Solicite ao Sr. Wandrey Mundin Ferreira Abraço. Quote Link to comment Share on other sites More sharing options...
kapiaba Posted December 3, 2021 Report Share Posted December 3, 2021 Bom dia. Infosys2, como você resolveu isso? Obg. abs. Quote Link to comment Share on other sites More sharing options...
infosys2 Posted March 30, 2022 Author Report Share Posted March 30, 2022 Nao resolvi nao parei o projeto Quote Link to comment Share on other sites More sharing options...
gilmer Posted March 31, 2022 Report Share Posted March 31, 2022 Bom Dia, O Harbour tem lib para libcurl, seria uma solução Quote Link to comment Share on other sites More sharing options...
infosys2 Posted March 31, 2022 Author Report Share Posted March 31, 2022 5 minutos atrás, gilmer disse: Bom Dia, O Harbour tem lib para libcurl, seria uma solução Sim eu vi esta lib conseguir fazer a parte de GET porem na parte de post nao achei nenhum exemplo mostrando como fazer um post e informar a chave key precizo de um exemplo de posto ou put onde tem que informar a chave Key Quote Link to comment Share on other sites More sharing options...
rochinha Posted March 31, 2022 Report Share Posted March 31, 2022 Amiguinhos, Não li as respostas anteriores e nem se alguém já deu solução mas mais aí meus 20 centavos: // curl -X POST http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula \ cUrlWS := "http://ws.prefeituradeatibaia.com.br/WSNfses/nfseresources/ws/v2/emissao/simula" oServerWS := Win_OleCreateObject("MSXML2.ServerXMLHTTP.6.0") With Object oServerWS :Open( "POST", cUrlWS, .F. ) // -H 'authorization: 999991-2EU2TPWLJBP2H57HL605K24778989PPP' \ :SetRequestHeader( "authorization", "999991-2EU2TPWLJBP2H57HL605K24778989PPP" ) // -H 'cache-control: no-cache' :SetRequestHeader( "cache-control", "no-cache" ) // -H 'content-type: application/xml' :SetRequestHeader( "content-type: application/xml" ) // -H 'postman-token: 25a25272-851b-1763-f96f-6ac0017ad209' \ :SetRequestHeader( "postman-token", "25a25272-851b-1763-f96f-6ac0017ad209" ) // -d ' XML A SER ENVIADO' :Send( memoread( 'XML A SER ENVIADO' ) ) Do While :readyState != 4 :WaitForResponse( 500 ) Enddo End Quote Link to comment Share on other sites More sharing options...
rochinha Posted March 31, 2022 Report Share Posted March 31, 2022 Amiguinhos, Deve-se usar SetRequestHeader par imputar variaveis e parâmetros como chaves, tokens ou keys: :SetRequestHeader( "Minha-Key", "9jj348ygfyrdd09rj3-8u54-sdlkewru854" ) Quote Link to comment Share on other sites More sharing options...
rochinha Posted March 31, 2022 Report Share Posted March 31, 2022 Amiguinhos, Não vejo também problema em usar interface com outros programas: ... if file( cPathDados+"curl.exe" ) cParameters := ' --get http://api.labelary.com/v1/printers/8dpmm/labels/4x6/0/' + ; ' --data-urlencode "' + charRem( chr(13)+chr(10), cEtiqueta ) + '" > ' + cArquivo2 cMacro := cPathDados+"ZPLCURL.BAT" cComando := cPathDados+"CURL.EXE " + cParameters // errhandle := fCreate( cMacro ) fWrite( errhandle, cComando ) fClose( errhandle ) // MsgRun( "Aguarde o termino do processo", "Envio da Etiqueta...", {|| WaitRun( cMacro, 0 ) } ) endif ... O curl.exe pode ser baixado deste link Quote Link to comment Share on other sites More sharing options...
infosys2 Posted March 31, 2022 Author Report Share Posted March 31, 2022 5 horas atrás, rochinha disse: Amiguinhos, Não vejo também problema em usar interface com outros programas: ... if file( cPathDados+"curl.exe" ) cParameters := ' --get http://api.labelary.com/v1/printers/8dpmm/labels/4x6/0/' + ; ' --data-urlencode "' + charRem( chr(13)+chr(10), cEtiqueta ) + '" > ' + cArquivo2 cMacro := cPathDados+"ZPLCURL.BAT" cComando := cPathDados+"CURL.EXE " + cParameters // errhandle := fCreate( cMacro ) fWrite( errhandle, cComando ) fClose( errhandle ) // MsgRun( "Aguarde o termino do processo", "Envio da Etiqueta...", {|| WaitRun( cMacro, 0 ) } ) endif ... O curl.exe pode ser baixado deste link Valeu Rochinha pelas dicas. Com certeza vai ajudar sim! rochinha 1 Quote Link to comment Share on other sites More sharing options...
infosys2 Posted April 1, 2022 Author Report Share Posted April 1, 2022 Em 31/03/2022 at 11:21, rochinha disse: Amiguinhos, Não vejo também problema em usar interface com outros programas: ... if file( cPathDados+"curl.exe" ) cParameters := ' --get http://api.labelary.com/v1/printers/8dpmm/labels/4x6/0/' + ; ' --data-urlencode "' + charRem( chr(13)+chr(10), cEtiqueta ) + '" > ' + cArquivo2 cMacro := cPathDados+"ZPLCURL.BAT" cComando := cPathDados+"CURL.EXE " + cParameters // errhandle := fCreate( cMacro ) fWrite( errhandle, cComando ) fClose( errhandle ) // MsgRun( "Aguarde o termino do processo", "Envio da Etiqueta...", {|| WaitRun( cMacro, 0 ) } ) endif ... O curl.exe pode ser baixado deste link Rochinha, tem como pegar o retorno da api quando consumir a API com um comando externo tipo curl.exe parametros Quote Link to comment Share on other sites More sharing options...
rochinha Posted April 2, 2022 Report Share Posted April 2, 2022 Amiguinhos, infosys2 use uma destas duas opções e veja se traz o resultado. O trecho acima foi só um exemplo de uso que nem chegou a ser solução para a entrada da thread. Só para exemplificar mesmo. cComando := cPathDados+"resposta=$(CURL.EXE " + cParameters + ") echo $resposta" ou cComando := cPathDados+"resposta=$(CURL.EXE --write-out " + cParameters + ") echo $resposta" ou cComando := cPathDados+"CURL.EXE " + cParameters +" > resposta" Quote Link to comment Share on other sites More sharing options...
Marca Posted April 11, 2022 Report Share Posted April 11, 2022 InfoSys2 poderia me chamar no Skype ? marcelomarca meu skype Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.