Got a 'How do I' question? Join 'Ask a Trainer' Monday to Friday, 11am to 4pm ET for instant help and pro tips!

The remote server returned an error: (400) Bad Request.

MandiC77984
Campaign Collaborator
0 Votes

Here is my code ..I am getting issue get respoms

plz resolve my issue asap

 

string CCusername = "****";
string CCpassword = "****";
string CCuri = "https://api.constantcontact.com/ws/customers/" + CCusername + "/activities";

string CClistUri = "https://api.constantcontact.com/ws/customers/" + CCusername + "lists/1";
string CCAPIKEY = "******";

string Email = form["Email"].ToString();
string Name = form["Name"].ToString();

Uri address = new Uri(CCuri);
WebRequest request = WebRequest.Create(address);
request.Credentials = new NetworkCredential(CCAPIKEY + "%" + CCusername, CCpassword);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";

StringBuilder data = new StringBuilder();
data.Append("activityType=" + HttpUtility.UrlEncode("SV_ADD", Encoding.UTF8));
data.Append("&data=" + HttpUtility.UrlEncode(("Email Address,First Name" + "\n"), Encoding.UTF8));
data.Append(HttpUtility.UrlEncode((Email + "," + Name + ","), Encoding.UTF8));
data.Append("&lists=" + HttpUtility.UrlEncode(CClistUri));

Byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
String st = String.Empty;
request.ContentLength = byteData.Length;

Stream postStream = request.GetRequestStream();
using (postStream)
{
postStream.Write(byteData, 0, byteData.Length);
}

WebResponse response = request.GetResponse();

using (response)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
st = reader.ReadToEnd();
}

0 REPLIES 0
Resources
Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Announcements

API Updates

Join our list to be notified of new features and updates to our V3 API.

Sign Up