[SOLVED] Creating a XML-RPC Client

Hello,

I am fairly new to Go, coming from the Perl world. I am trying to re-implement a few things I wrote in Perl with Go to get some experience and learn the ropes.

One of my scripts is an XML-RPC client (using Perl’s Frontier::Client module). As Perl does not have this built-in I chose github.com/kolo/xmlrpc from the options in the Go universe.

I am now stuck at trying to authenticate and the documentation is sparse, not enabling me to figure it out myself. I have to send a username and a password and should get back a session key. Here is what I tried so far

        client, _ := xmlrpc.NewClient("http://localhost/rpc/api", nil)
        type Credentials struct {
                Username, Password      string
        }
        var creds = Credentials{"admin","admin1"}
        client.Call("auth.login", &creds, &sessionkey)

Looking at a tcpdump, I see that the username and password field are transmitted inside a <struct> tag, which is not what the server expects and so I don’t get a session key.

Any pointers would be greatly appreciated.

Cheers, Lordy

I have found the solution myself, looking at other source code that uses the same module:

The Login function there did what I need and I changed my code to be

        creds := make([]interface{}, 2)
        creds[0] = "admin"
        creds[1] = "admin1"

        client.Call("auth.login", creds, &sessionkey)

I now get a valid sessionkey and can continue :smiley:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.