Search code examples
vala

How would I create a HTTPS request in vala?


I am trying to create a github issue app in vala and need to get the list of issues from https://api.github.com/repos/vmg/redcarpet/issues?state=closed.

I have tried using this example in my code but this is not working for SSL. https://wiki.gnome.org/Projects/Vala/GIONetworkingSample

I have also tried soup but this seems to have a problem where it can't find its dev headers.

Any help would be much appreciated.


Solution

  • You have to set the tls property to true on the SocketClient object, and you have to connect to the correct port (443). This works for me:

    var client = new SocketClient() { tls = true };
    // Or do this (does the same):
    // var client = new SocketClient();
    // client.tls = true;
    var socket = client.connect_to_host (hostname, 443);
    

    If the server you are connecting to are using a self-signed certificate, you also have to change the TLS validation flags: client.set_tls_validation_flags (...);

    But it's probably easier with Soup, as another commenter pointed out.

    God luck. Vala is a sweet language.