I use WHMCS API. I am trying to use their API to make request.That api need that array need to be serialize and in base64_encode. They give example with php and I try to convert it into C# code but it not work.
PHP CODE :
$values["customfields"] = base64_encode(serialize(array("1"=>"Google")));
My C# Code for this :
CustomFields[] cf = new CustomFields[2];
CustomFields cf0 = new CustomFields();
cf0.number = "16";
cf0.value = WebSiteTitle;
CustomFields cf1 = new CustomFields();
cf1.number = "14";
cf1.value = NewDomain;
cf[0] = cf0;
cf[1] = cf1;
byte[] bytecf = ObjectToByteArray2(cf);
String CString = Convert.ToBase64String(bytecf);
form.Add("customfields", CString);
private static byte[] ObjectToByteArray2(Object obj)
{
if (obj == null)
return null;
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, obj);
return ms.ToArray();
}
[Serializable]
public class CustomFields
{
public string number { get; set; }
public string value { get; set; }
}
Did I do something wrong? Because when I try to make request it not work and not adding this field where I want to add.