Search code examples
c#flurl

Using custom protocol


I would like to use another protocol than http(s):// in particular i want to build a URL that begins with vrchat:// but for some reason it always kills the second /

        var url = "vrchat://".AppendPathSegment("launch");
        if (!string.IsNullOrWhiteSpace(innerString)) {
            url.SetQueryParam("id", innerString, true);
        }
        //url.SetQueryParam("ref", "vrchat.com");
        Console.WriteLine("Connecting to {0}", url);

Results in

Connecting to vrchat:/launch?id=wrld_b805006c-bec7-4179-958a-5a9351e48d5c

Solution

  • You're not actually appending a path segment there, you're appending an authority. The main behaviors of AppendPathSegment over plain old string concatenation are encoding and ensuring 1 and only 1 / character between segments, which is most likely causing what you're seeing. You don't want or need those behaviors here, so (assuming authority is variable) just use string concatenation:

    var url = "vrchat://" + authority;
    // or
    var url = $"vrchat://{authority}";