Re: Http in an extension



You need to use libsoup.

Here is some sample code, since I'm currently trying to do it myself
and boy I wish I had it as well.  The code is for synchronous
interaction.  That's why there is no main loop.  The only difference
is that you need to use soup_session_queue_message with a callback.
Anyways, good luck!

const Glib = imports.gi.GLib;
const Gio = imports.gi.Gio;
const Mainloop = imports.mainloop;
const Gettext = imports.gettext;
const Soup = imports.gi.Soup;

function main ()
{
    let url="http://httpbin.org/ip";;
    let _httpSession = new Soup.Session();
    _httpSession.set_property('ssl-strict', false); // use if you are
doing a https://
    Soup.Session.prototype.add_feature.call (_httpSession, new
Soup.ProxyResolverDefault());
    _httpSession.connect("authenticate", _httpAuth);

    send (_httpSession,url);

};

function send (_lhttpSession,lurl) {

    let cancellable = new Gio.Cancellable ();
    let results = 0;

    let msg = Soup.Message.new ("GET",lurl);

    results = _lhttpSession.send_message(msg,cancellable);
    let content = msg.response_body.data;

    print (content);

};

// this part is wrong, and I'm not sure why, I get some warnings.  You
can probably ignore if you're not
// using authentication.

function _httpAuth(authObj,myusername,mypassword)
{
    print ("I am here");
    let myusername="user";
    let mypassword="password";
};


main();

On Fri, Dec 20, 2013 at 6:56 AM, Megh Parikh <meghjp gmail com> wrote:
How to interact with http in an extension or issue system commands

_______________________________________________
gnome-shell-list mailing list
gnome-shell-list gnome org
https://mail.gnome.org/mailman/listinfo/gnome-shell-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]