Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

HTTP Request response unreliable

mobilefirstmobilefirst Germany
edited August 2016 in Mongoose OS

Hi Cesanta Team,

we use a function like below. Sometimes the request works as expected
but sometimes the response is kind of broken and the device start to reboot. Any idea what the problem is ?

function HttpRequest(body, cb) {
        Http.request({
            hostname: 'xx.196.8.xx',                        
            port: 8545,
            path: '/',
            method: 'POST',
            headers: { 
                "Content-Type": "application/json", 
                "Content-Length": body.length    
            }
        }, function(response) {    
            print('response: ', response);                                                           
            try {
                respobj = JSON.parse(response.body);
                cb(respobj)
            } catch(err) {
                print('error in response. can not parse reponse: ', response);
                cb([])
            }            
        })
        .write(body, "utf8")        
        .end(print('HttpRequest finished'))
        .setTimeout(5000, function() {
            print('HttpRequest aborted after timeout')
            this.abort(); 
            cb([]);  
        });
     }

Best regards

Juergen

Comments

Sign In or Register to comment.