Web service

Web service

Postby jair » Sun Jul 25, 2021 3:05 pm

¡Traté de hacerlo de esta manera pero no funcionó!

¿Alguien podría dar sugerencias sobre cómo hacer esto?

Code: Select all  Expand view

#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-QLx2k6w7u0nEAOWld2Po" )

// envio xml
oHttp:send("<consulta><inscricaoMunicipal>999991</inscricaoMunicipal><codigoVerificacao>2978937BMA</codigoVerificacao></consulta>")

cRespuesta:= oHttp:responseText
? cRespuesta

 
return nil
 


Ejemplos contenidos en la documentación

Code: Select all  Expand view

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
 
jair
 
Posts: 57
Joined: Sun Aug 27, 2017 7:18 pm



Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 40 guests