Request


Object Hierarchy:

Soup.Request Soup.Request Soup.Request GLib.Object GLib.Object GLib.Object->Soup.Request GLib.Initable GLib.Initable GLib.Initable->Soup.Request

Description:

[ CCode ( type_id = "soup_request_get_type ()" ) ]
[ Version ( since = "2.42" ) ]
public class Request : Object, Initable

A request to retrieve a particular URI.

Example: Request API, sync:

public static int main (string[] args) {
try {
// Create a session:
Soup.Session session = new Soup.Session ();

// Request a file:
Soup.Request request = session.request ("http://api.valadoc.org/soup-samples/my-secret.txt");
InputStream stream = request.send ();

// Print the content:
DataInputStream data_stream = new DataInputStream (stream);

string? line;
while ((line = data_stream.read_line ()) != null) {
print (line);
print ("\n");
}
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
}
return 0;
}

valac --pkg libsoup-2.4 request-sync.vala

Example: Request API, async:

private static async void read_lines_async (InputStream stream) throws IOError {
DataInputStream data_stream = new DataInputStream (stream);
string line;

while ((line = yield data_stream.read_line_async ()) != null) {
print (line);
print ("\n");
}
}

public static int main (string[] args) {
MainLoop loop = new MainLoop ();

// Create a session:
Soup.Session session = new Soup.Session ();
session.use_thread_context = true;

// Request a file:
try {
Soup.Request request = session.request ("http://api.valadoc.org/soup-samples/my-secret.txt");
request.send_async.begin (null, (obj, res) => {
// print the content:
try {
InputStream stream = request.send_async.end (res);
read_lines_async.begin (stream, (obj, res) => {
// Exit
loop.quit ();
});
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
}
});
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
}

loop.run ();
return 0;
}

valac --pkg libsoup-2.4 request-async.vala
All known sub-classes:

Namespace: Soup
Package: libsoup-2.4

Content:

Properties:

Creation methods:

Methods:

Inherited Members:

All known members inherited from class GLib.Object
All known members inherited from interface GLib.Initable



2022 vala-language.org