简体   繁体   中英

BeagleBone Black sending data to a web server using BoneScript

How do I send data (via ajax post or get) from BeagleBone Black to a web server using BoneScript?

As I understand, XMLHttpRequest does not exist. Is there another approach?

I found the solution: In fact, I see this operation is not related to beaglebone. It relates to nodejs. So, the key is require('http') by node.

var http = require('http');

http.get('http://www.example.com', function(response) {
    var response_data = '';

    response.on('data', function(chunk) {
        response_data += chunk;
    })
    .on('end', function() {
        console.log(response_data);
    })
    .on('error', function(e) {
        console.log('Error: ' + e.message);
    });
});

OR if you want to do that simpler, you can use Requistify

npm install requestify

After installed you can use it like:

var requestify = require('requestify');

// GET Example
requestify.get('http://example.com').then(function(response) {
    // Get the response body (JSON parsed - JSON response or jQuery object in case of XML response)
    response.getBody();

    // Get the response raw body
    response.body;
});

// POST example
requestify.post('http://example.com', {
    hello: 'world'
})
.then(function(response) {
    // Get the response body
    response.getBody();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM