tests/soup.js
[gitlive] / tests / soup.js
1 #!/usr/bin/env seed
2
3 Soup = imports.gi.Soup;
4 Netrc = imports['../Netrc.js'].Netrc;
5
6 GLib = imports.gi.GLib;
7
8 var session = new Soup.SessionSync();
9 File  = imports['../File.js'].File;
10
11  
12 // Soup.URI is a struct.
13 var uri = new Soup.URI.c_new("http://www.roojs.com/admin.php/Roo/Events");
14 //var uri = new Soup.URI.c_new("http://www.roojs.com/head.php");
15
16 var msg = new Soup.Message({method:"POST", uri:uri});
17 //var msg = new Soup.Message({method:"GET", uri:uri});
18
19 // post..
20 buftxt =  "remarks=test";
21  
22 msg.set_request('application/x-www-form-urlencoded', Soup.MemoryUse.COPY, buftxt, buftxt.length)
23
24
25 var auth = new Soup.Auth.c_new(Soup.AuthBasic.type, msg, "Basic realm=\"Test\"");
26  
27 var authvals = Netrc.forHost('git.roojs.com');
28
29 auth.authenticate(authvals.login ,authvals.password);
30 var authmsg = auth.get_authorization(msg);
31 //print(authmsg);
32 msg.request_headers.append('Authorization', authmsg)
33
34 //request.headers_append...
35 var status = session.send_message(msg);
36 // session.queue_message(function(ses, msg) {
37 //
38 //}
39 //)
40 print(status);
41
42 print(msg.response_body.data);