Hi, I've worked two days on trying to get a C# to connect to a Drupal 6 site by using xmlrpc and fetch a node's title and body. I've managed to log in and have verified that I'm logged in by checking the log in my watchdog. However, when I try to make a new call and get a node, I always get 401 Access Denied, even though I use the same sessid as I did when I logged in.
I hope anyone of you has a better understanding of this then I have.
All of the functions I use are copied from this example: http://drupal.org/node/308629
This is my code that gets executed when I press the View Node button in my app:
Whole code is here: http://pastebin.com/g2C1e3u1
{
IDrupalServices drupal = XmlRpcProxyGen.Create();
Drupal cnct = drupal.Connect();
try
{
string timestamp = GetUnixTimestamp();
string nonce = GetNonce(10);
string domain = "domain.ltd";
string key = textapi.Text;
string hash = GetHMAC(timestamp + ";" + domain + ";" + GetNonce(10) + ";user.login", key);
Console.Out.WriteLine("SSID: " + cnct.sessid);
Drupal lgn = drupal.Login(hash, domain, timestamp, nonce, cnct.sessid, username.Text, password.Text);
}
catch (Exception ex) { Console.WriteLine(ex.Message); }
try
{
string timestamp = GetUnixTimestamp();
string nonce = GetNonce(10);
string domain = "domain.ltd";
string key = textapi.Text;
string hash = GetHMAC(timestamp + ";" + domain + ";" + nonce + ";node_resource.retrieve", key);
string[] fields = new string[] { };
XmlRpcStruct nodeload = drupal.NodeLoad(hash, domain, timestamp, nonce, cnct.sessid, 10796, fields);
textBox2.Text = nodeload["title"].ToString();
textBox1.Text = nodeload["body"].ToString();
}
catch (Exception ex) { Console.WriteLine(ex.Message); }
Comments
Comment #1
NeoID CreditAttribution: NeoID commentedForgot to change fix a line before posting:
string hash = GetHMAC(timestamp + ";" + domain + ";" + GetNonce(10) + ";user.login", key);
should have been:
string hash = GetHMAC(timestamp + ";" + domain + ";" + nonce + ";user.login", key);
Comment #2
kylebrowning CreditAttribution: kylebrowning commentedYou need to store the cookie in session thats returned from user.login
Comment #3
NeoID CreditAttribution: NeoID commentedI'm sorry, but I don't have an idea how to do that, do you have an example?
I thought the cnct.sessid was the only thing I needed to include in order to keep the session alive?
Comment #4
marcingy CreditAttribution: marcingy commentedThe source code here http://www.gizra.com/content/drutnet-drupal-net-api is likely to help you understand how to do this
Comment #6
Tess BakkerOke, after too many hours of searching en debuging I found the answer:
Do not use cnct.sessid when you're logged in, but use lgn.sessid.
That's all :)