Question

I want to connect to vCloud Dirrector through rest api. My correct curl command to login is

curl -i -k -H "Accept:application/*+xml;version=1.5" -u "administrator@System:qwe123" -X POST https://172.16.8.240/api/sessions

But I can't write it on D.

import std.stdio;
import std.string;
import std.net.curl;

int main(string[] argv)
{
    auto httpClient = HTTP();
    httpClient.clearRequestHeaders();
    httpClient.addRequestHeader("Accept", "application/*+xml;version=1.5");
    httpClient.authenticationMethod = HTTP.AuthMethod.basic;
    httpClient.setAuthentication("administrator", "System:qwe123");
    try
    {
        auto a = post("https://172.16.8.240/api/sessions", "", httpClient);
    }
    catch (CurlException ex)
    {
        writeln(ex);
    }

    return 0;
}

I have CurlException

std.net.curl.CurlException@std\net\curl.d(3504): Peer certificate cannot be auth
enticated with given CA certificates on handle 1D53758
----------------
0x00409456 in stdexceptionenforceEx at C:\D\dmd2\src\phobos\std\exception.d(527)

0x0043D88A in stdnetcurlCurl_check
0x00408742 in stdnetcurlpost at C:\D\dmd2\src\phobos\std\net\curl.d(423)
0x004020D4 in D at C:\Users\yrybalka\documents\visual studio 2013\Projects\visua
lStudioD\visualStudioD\main.d(15)
0x0042E670 in rtdmain2_d_run_mainrunAll__lambda1
0x0042E643 in rtdmain2_d_run_mainrunAll
0x0042E55B in _d_run_main
0x0042E378 in main at C:\Users\yrybalka\documents\visual studio 2013\Projects\vi
sualStudioD\visualStudioD\SuperClass.d(3)
0x0046C2C9 in mainCRTStartup
0x76CA495D in BaseThreadInitThunk
0x778D98EE in RtlInitializeExceptionChain
0x778D98C4 in RtlInitializeExceptionChain

Maybe should I use some compiler key for https? Or is my code wrong?

Was it helpful?

Solution

As a workaround at least, if you added

httpClient.verifyPeer = false;
httpClient.verifyHost = false;

in there before performing the request, it should silence this error (by not actually checking the certificate). I don't know how to add your root certificates though, maybe someone else can answer with that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top