aptinno Posted December 17, 2012 Share Posted December 17, 2012 (edited) Hello, I have made a wrapper for the API in C#, which I plan on making available to the community as an open source project. I seem to be having issues posting base64 encoded serialized arrays, like those used for "customfields". I've read other posts and see that many users have had inquiries on this issue. I understand that the in the case of "customfields", the NameValueCollection's name (key) should correspond to the "Custom Field Id", however my posted data is still being ignored. Anyone have an example of posting the base64 encoded serialized arrays using .NET's WebClient? I have attempted to, both, base64 encode a serialized NameValueCollection (example 1), as well as adding each field explicitly (example 2)-- neither seems to work. NameValueCollection nvp = new NameValueCollection(); nvp.Add("username", "xxx"); nvp.Add("password", "xxx"); nvp.Add("action", "xxx"); ... // add custom fields NameValueCollection customFields = new NameValueCollection(); customFields.Add("1", "Field1 Value"); customFields.Add("2", "Field2 Value"); nvp.Add("customfields", SerializeBase64(customFields)); WebClient client = new WebClient(); client.UploadValues("url", nvp); public static string SerializeBase64(object o) { // Serialize to a base 64 string byte[] bytes; long length = 0; MemoryStream ws = new MemoryStream(); BinaryFormatter sf = new BinaryFormatter(); sf.Serialize(ws, o); length = ws.Length; bytes = ws.GetBuffer(); string encodedData = bytes.Length + ":" + Convert.ToBase64String(bytes, 0, bytes.Length, Base64FormattingOptions.None); return encodedData; } Example 2 NameValueCollection nvp = new NameValueCollection(); nvp.Add("action", "xxx"); nvp.Add("customfields[1]", "value"); // nvp.Add("customfields["1"]", "value"); // also tried WebClient client = new WebClient(); client.UploadValues("url", nvp); Thank you in advance. Edited December 17, 2012 by aptinno 0 Quote Link to comment Share on other sites More sharing options...
sahil kaundal Posted March 6, 2013 Share Posted March 6, 2013 i have implemented custom filed with c# asp.net . code is : form.Add("customfield[1]", model.number.ToString()); If anyone have still problem then contact me here..sahil.mohali@gmail.com 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.