2

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?

1

1 Answer 1

3

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.

2
  • 401 means unauthorized, so check your username and password. From the curl command line, looks like your username should be "adminstrator@System" and the password "qwe123", instead of what you have with system being in the password field of the setAuthentication call. Dec 10, 2013 at 23:03
  • I had to think twice before asking this simple question. It helps, thank you. Dec 11, 2013 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.