Hi Guys,
I'm adding contacts to the lists thru activities. I'm getting The remote server returned an error: (400) Bad Request. Code is as follows
HttpWebRequest oRequest = null;
oRequest = (HttpWebRequest)LoginCredReq("https://api.constantcontact.com/ws/customers/username/activities");
oRequest.ContentType = "multipart/form-data; boundary=" + PostData.boundary;
oRequest.Method = "POST";
PostData pData = new PostData();
Encoding encoding = Encoding.UTF8;
Stream oStream = null;
pData.Params.Add(new PostDataParam("activityType", "SV_ADD", PostDataParamType.Field));
pData.Params.Add(new PostDataParam("lists", "http://api.constantcontact.com/ws/customers/username/lists/1", PostDataParamType.Field));
pData.Params.Add(new PostDataParam("data", "C:\\test.xls","file", PostDataParamType.File));
byte[] buffer = encoding.GetBytes(pData.GetPostData());
oRequest.ContentLength = buffer.Length;
oStream = oRequest.GetRequestStream();
oStream.Write(buffer, 0, buffer.Length);
oStream.Close();
HttpWebResponse oResponse = (HttpWebResponse)oRequest.GetResponse();
/// <summary> /// Returns the parameters array formatted for multi-part/form data
{
{
sb.AppendLine(
{
sb.AppendLine(
sb.AppendLine(
sb.AppendLine();
sb.AppendLine(p.Value);
}
{
sb.AppendLine(
sb.AppendLine();
sb.AppendLine(p.Value);
}
}
sb.AppendLine(
}
}
The only issue I can see by looking at this is that you are using an excel file which doesn't work properly in C#. I would attempt to upload a .csv file with this and see if this has better results. If not, if you want to zip your project (or classes) up and send it over to our webservices support team, I would be happy to take a closer look at this. Thanks.
David J
Thanks so much. I'll try to upload the csv file and let you know result.