question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TIMEOUT constante

See original GitHub issue

Olá! Passei a receber vários retornos de TIMEOUT constantemente das requests que fazia utilizando a package. Fiz alguns testes, e vi que se resolviam quando eu adicionei https em ambos endereços de consulta, ficando assim:

this.calcPrecoUrl = 'https://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx?wsdl';
this.cepUrl       = 'https://viacep.com.br/ws/{CEP}/json';

Daí pararam todos TIMEOUT que recebia. Há algum impedimento para essa alteração? Digo, algum motivo pra usar http ao invés de https?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

6reactions
OmarOmeiricommented, Apr 13, 2020

@educkf , então tive que abandonar o uso deste módulo. Porém descobri que não é muito dificil fazer esse request independentemente. Segue minha solução, se for te ajudar. Obs: Eu estou usando Node.js com express e faço essa operação dentro de uma função da API.

var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var parseString = require('xml2js').parseString;

router.post('/frete-sedex', [
        check('cep', 'Informe o CEP.').not().isEmpty()
    ], async(req,res) =>{
    
        const errors = validationResult(req);
        if (!errors.isEmpty()){
            return res.status(400).json({errors:errors.array()});
        };
    
            const {cep} = req.body;
    
        try{
    
    
            var xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function() {
                
                if (this.readyState === 4) {
                    res.type('application/xml');
                    parseString(this.responseText, function (err, result) {
                        const response = result.Servicos.cServico[0];
                        
                        return res.send(response);
                    });
                    
                };
            };
    
            xhr.open("GET", `http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?sCepOrigem=81200100&sCepDestino=${cep}&nVlPeso=1&nCdFormato=1&nVlComprimento=20&nVlAltura=20&nVlLargura=20&sCdMaoPropria=n&nVlValorDeclarado=0&sCdAvisoRecebimento=n&nCdServico=04014&nVlDiametro=0&StrRetorno=xml&nIndicaCalculo=3`);
            xhr.send();
            
    
         
    
    
        }catch(err){
            console.error(err);
            return res.status(500).send('Server error.')
        }
    });
0reactions
pierrefrotacommented, Nov 6, 2020

@OmarOmeiri esse erro de apenas um serviço por consulta é porque você tem que adicionar o código administrativo e a senha do contrato, geralmente só empresas tem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TIMEOUT constant - constant library - Dart API - Contentstack
API docs for the TIMEOUT constant from the constant library, for the Dart programming language. ... TIMEOUT top-level constant. int const TIMEOUT ...
Read more >
TIMEOUT constant - PositionError class - dart:html library - Dart API
API docs for the TIMEOUT constant from the PositionError class, for the Dart programming language.
Read more >
timeout constant - chflutterview library - Dart API - Pub.dev
API docs for the timeout constant from the chflutterview library, for the Dart programming language.
Read more >
timeout constant - NERtcConnectionStateChangeReason class ...
API docs for the timeout constant from the NERtcConnectionStateChangeReason class, for the Dart programming language.
Read more >
COMMTIMEOUTS (winbase.h) - Win32 apps | Microsoft Learn
A constant used to calculate the total time-out period for read operations, in milliseconds. For each read operation, this value is added to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found